I am opening a pdf file with my default application using subprocess.call, like this:
subprocess.call(["xdg-open", pdf], stderr=STDOUT)
But, when running that, the process is attached to the terminal and I want to detach it. Basically, I want to run that and then be able to use the terminal for other stuff.
How would I go about doing that?
You can use Popen
for this.
from subprocess import Popen, PIPE, STDOUT
p = Popen(["xdg-open", pdf], stderr=STDOUT, stdout=PIPE)
# do your own thing while xdg-open runs as a child process
output, _ = p.communicate()
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.