I am using python 3.6.3 and subprocess module to run another python script
# main.py
#!/bin/env python
from subprocess import Popen,PIPE
from sys import executable
p = Popen([executable, 'test.py', 'arg1'],shell=True, stdout=PIPE)
p.wait()
print(p.stdout.read().decode())
and
# test.py
import sys
print(sys.argv)
I expect it will run and execute test.py. However, it opens an python interpreter in interactive mode!
I tested shell=False option, it works. I tested string form rather than list form of args, it works.
I am not sure if it is a bug or not.
stdinis connected to a TTY. The default of Popen is for the default io handles to be inherited, which connects the second interpreter to your TTY as well. Try passingstdin=None.python3 test.py arg1from my terminal (where stdin is a tty), it runs the script without dropping to an interactive shell.