SysCommand now sets working_directory on SysCommandWorker. Also made it so the parent process moves back to the original working directory, leaving the child process in the target working directory. (#1142)

This commit is contained in:
Anton Hvornum 2022-05-08 18:36:32 +02:00 committed by GitHub
parent 5a1bd83132
commit 80cee500e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

View File

@ -352,7 +352,6 @@ class SysCommandWorker:
# only way to get the traceback without loosing it.
self.pid, self.child_fd = pty.fork()
os.chdir(old_dir)
# https://stackoverflow.com/questions/4022600/python-pty-fork-how-does-it-work
if not self.pid:
@ -371,6 +370,9 @@ class SysCommandWorker:
log(f"{self.cmd[0]} does not exist.", level=logging.ERROR, fg="red")
self.exit_code = 1
return False
else:
# Only parent process moves back to the original working directory
os.chdir(old_dir)
self.started = time.time()
self.poll_object.register(self.child_fd, EPOLLIN | EPOLLHUP)
@ -457,7 +459,14 @@ class SysCommand:
if self.session:
return self.session
with SysCommandWorker(self.cmd, callbacks=self._callbacks, peak_output=self.peak_output, environment_vars=self.environment_vars, remove_vt100_escape_codes_from_lines=self.remove_vt100_escape_codes_from_lines) as session:
with SysCommandWorker(
self.cmd,
callbacks=self._callbacks,
peak_output=self.peak_output,
environment_vars=self.environment_vars,
remove_vt100_escape_codes_from_lines=self.remove_vt100_escape_codes_from_lines,
working_directory=self.working_directory) as session:
if not self.session:
self.session = session