This commit is contained in:
Paul Gauthier 2024-08-31 15:50:50 -07:00
parent 0c5cd64b83
commit 22318a3160

View file

@ -18,7 +18,7 @@ def run_cmd(command, verbose=False):
def run_cmd_subprocess(command, verbose=False): def run_cmd_subprocess(command, verbose=False):
if verbose: if verbose:
print("run_cmd_subprocess:", command) print("Using run_cmd_subprocess:", command)
try: try:
process = subprocess.Popen( process = subprocess.Popen(
command, command,
@ -52,7 +52,7 @@ def run_cmd_pexpect(command, verbose=False):
:return: A tuple containing (exit_status, output) :return: A tuple containing (exit_status, output)
""" """
if verbose: if verbose:
print("run_cmd_pexpect:", command) print("Using run_cmd_pexpect:", command)
output = BytesIO() output = BytesIO()
@ -64,17 +64,17 @@ def run_cmd_pexpect(command, verbose=False):
# Use the SHELL environment variable, falling back to /bin/sh if not set # Use the SHELL environment variable, falling back to /bin/sh if not set
shell = os.environ.get("SHELL", "/bin/sh") shell = os.environ.get("SHELL", "/bin/sh")
if verbose: if verbose:
print("shell:", shell) print("With shell:", shell)
if os.path.exists(shell): if os.path.exists(shell):
# Use the shell from SHELL environment variable # Use the shell from SHELL environment variable
if verbose: if verbose:
print("pexpect.spawn with shell:", shell) print("Running pexpect.spawn with shell:", shell)
child = pexpect.spawn(shell, args=["-c", command], encoding="utf-8") child = pexpect.spawn(shell, args=["-c", command], encoding="utf-8")
else: else:
# Fall back to spawning the command directly # Fall back to spawning the command directly
if verbose: if verbose:
print("pexpect.spawn without shell") print("Running pexpect.spawn without shell.")
child = pexpect.spawn(command, encoding="utf-8") child = pexpect.spawn(command, encoding="utf-8")
# Transfer control to the user, capturing output # Transfer control to the user, capturing output