I am trying to launch a python script from another python script in a new shell window. So far I'm unable to do it. Does anyone knows how can I accomplish this?
for example
import subprocess
process = subprocess.Popen('test.py', shell=True, stdout=subprocess.PIPE)
process.wait()
print (process.returncode)
when I'll run this script, it should launch 'test.py' in a new a new shell window.
I'm using linux, but it will be very helpful if you can provide solution for windows too.
Here's how you could do it on Debian-like systems:
import subprocess
import shlex
process = subprocess.Popen(
shlex.split("""x-terminal-emulator -e 'bash -c "test.py"'"""), stdout=subprocess.PIPE)
process.wait()
print (process.returncode)
Something like it should work for any *nix system.
Many thanks to eudoxos for pointing out x-terminal-emulator
!
Instead of launching a shell, launch a terminal running your script. On Linux, xterm -e test.py
; the Windows equivalent would be cmd.exe test.py
I believe (but I could be wrong).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.