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

Question:

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?

Asked By: Adobe

||

Answers:

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.

Answered By: obmarg

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

Answered By: Russel Winder

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

Fixed using subprocess:

import subprocess

subprocess.run("cmd")
Answered By: Max Farsikov
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.