Skip to content

Commit

Permalink
Playing with exposing the subprocess while inside run
Browse files Browse the repository at this point in the history
  • Loading branch information
tfoote committed Feb 13, 2025
1 parent 13b764c commit b16b79b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/rocker/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ def __init__(self, active_extensions, cliargs, base_image):

self.dockerfile = generate_dockerfile(active_extensions, self.cliargs, base_image)
self.image_id = None
self.run_subprocesses = []

def build(self, **kwargs):
with tempfile.TemporaryDirectory() as td:
Expand Down Expand Up @@ -417,7 +418,10 @@ def run(self, command='', **kwargs):
print(f"Logging output to file {console_output_file}")
print("Executing command: ")
print(cmd)
p = subprocess.run(shlex.split(cmd), check=True, stdout=consoleout_fh if console_output_file else None, stderr=subprocess.STDOUT)
p = subprocess.Popen(shlex.split(cmd), stdout=consoleout_fh if console_output_file else None, stderr=subprocess.STDOUT)
self.run_subprocesses.append(p)
p.wait()
self.run_subprocesses.remove(p)
return p.returncode
except subprocess.CalledProcessError as ex:
print("Non-interactive Docker run failed\n", ex)
Expand All @@ -427,9 +431,11 @@ def run(self, command='', **kwargs):
print("Executing command: ")
print(cmd)
p = pexpect.spawn(cmd)
self.run_subprocesses.append(p)
with SIGWINCHPassthrough(p):
p.interact()
p.close(force=True)
self.run_subprocesses.remove(p)
return p.exitstatus
except pexpect.ExceptionPexpect as ex:
print("Docker run failed\n", ex)
Expand Down

0 comments on commit b16b79b

Please sign in to comment.