python - What is the correct way to switch from os.system to Popen for spawning an interactive shell? -
i trying rid of os.system in python code, of done, have 1 line can't seem convert.
os.system('/bin/sh -i -c "/bin/runner catch exts"')
so far things tried:
p = subprocess.popen(['/bin/sh', '-i', '-c', '/bin/runner catch exts'])
that returns:
/bin/sh: 1: cannot set tty process group (no such process)
edit:
instead of running custom runner, i've tried "ls" , still same error.
os.system('/bin/sh -i -c "ls"') # works fine
now trying convert --
p = subprocess.popen(['/bin/sh', '-i', '-c', 'ls']) # doesn't work
returns:
/bin/sh: 1: cannot set tty process group (no such process)
trying (this shouldn't work, suggested user in comments):
p = subprocess.popen('/bin/sh -i -c "ls"')
returns:
oserror: [errno 2] no such file or directory
interactive shells aren't possible popen
. subprocess
module designed give full control on stdin , stdout of child process can talk it.
an interactive shell, on other hand, needs tty (a terminal) , python should leave i/o streams alone. use case, can try pty
module instead or stay os.system()
Comments
Post a Comment