ENV: Oracle Linux 9, Python 3.9
I have a script which 1) installs dependencies for the second script from a given collection of WHL files, and 2) launches the “action” script once the dependencies are installed. That all seems to be working well.
def spawn_config_script_and_die(program, exit_code=0):
subprocess.Popen(program)
sys.exit(exit_code)
spawn_config_sript_and_die(['python3', 'confi_script.py', '-H', host_name, '-l', log_level, '-p', config_path])
The issue that I am having is that “input” commands do not wait for user input when the second script is launched from the first. The script just proceeds as if the user pressed “Enter” without providing a legitimate response. If I run the second script directly, “input” commands work fine. I’m sure this is some simple/known issue, but I’m just not finding/seeing it.
I tried to exit the first script once the second script was launched, but that didn’t make any difference.
5
As Tim Roberts mentioned in the comments, stdin=sys.stdin
needed to be passed to the script being called. However, I was unable to do so with subprocess.Popen()
. I had to use subprocess.run()
in order to successfully pass stdin=sys.stdin
.
1