Adobe
Adobe

Reputation: 13487

Does Python's os.system() wait for an end of the process?

The Python manual says nothing about whether os.system("cmd") waits or not for a process to end:

To quote the manual:

Execute the command (a string) in a subshell.

It looks like it does wait (same behaviour as Perl's system). Is this correct?

Upvotes: 34

Views: 48647

Answers (3)

Max Farsikov
Max Farsikov

Reputation: 2763

On Mac it waits, but on Linux it does not (Debian, python 3.7.3).

Fixed using subprocess:

import subprocess

subprocess.run("cmd")

Upvotes: 3

Russel Winder
Russel Winder

Reputation: 3804

Yes it does. The return value of the call is the exit code of the subprocess.

Upvotes: 37

obmarg
obmarg

Reputation: 9569

The manual doesn't explicitly say, but it does imply that it waits for the end of the process by saying that the return value is the return value of the program.

So to answer your question, yes it does wait.

Upvotes: 15

Related Questions