I am running a program which runs terminal codes based on the input recieved by the user on my Raspberry Pi. I want the process to run on a different terminal which is opened by my python code. For this on my Ubuntu machine I did
os.system("gnome-terminal -x google-chrome") #if i wanted to open chrome
But this is not an option on raspbian stretch. I want to know how I can perform similar functions on my raspberry pi
I had asked a similar question here . Refer to it to get a better understanding of what I am asking
I have Python 3.5.3 on the Raspberry Pi model 2 B running Raspbian Stretch
It sounds you do not necessarily want to spawn a new terminal emulator to run a process from, but just want that the process runs side-by-side with your Python code. You can spawn new processes in a more flexible way than os.system
with the subprocess
module.
import subprocess
subprocess.Popen("google-chrome", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
# Python code continues executing as soon as the process is spawned
print("Hello, World!")
The stdout
and stderr
arguments state that the output should be discarded (ie redirected to /dev/null
).
Note that by default Popen
does not use the shell to run your command. If you want to emulate the behaviour of os.system
more closely, use shell=True
as an argument to Popen
. As with os.system
this can have security implications!
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.