iamatrain
iamatrain

Reputation: 131

How to detach a program ran by subprocess.call?

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?

Upvotes: 3

Views: 3679

Answers (1)

blhsing
blhsing

Reputation: 106553

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()

Upvotes: 4

Related Questions