The subprocess call suite

The subprocess module provides another function that makes process spawning a safer operation than using Popen(). The subprocess call() function waits for the called command/program to finish reading the output. It supports the same arguments as the Popen() constructor, such as shell, executable, and cwd, but this time, your script will wait for the program to complete and populate the return code without the need to communicate().

If you inspect the call() function, you will see that it's actually a wrapper around the Popen() class, but with a wait() function that waits until the end of the command before returning the output:

import subprocesssubprocess.call(["ifconfig", "docker0"], stdout=subprocess.PIPE, stderr ...

Get Hands-On Enterprise Automation with Python. now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.