Python subprocess is an inbuilt module that enables you to start the new applications from your Python program. The subprocess module provides a consistent interface for creating and working with additional processes.
Python subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes.
In the official python docs, we can read that the subprocess should be used for accessing system commands. The subprocess module enables us to spawn processes, connect to their input/output/error pipes, and receive their return codes.
The suggested approach to invoking subprocesses is to use the run() function for all use cases it can handle. For more advanced use cases, the underlying Popen interface can be used directly.
The run() function was added in Python 3.5; if you need to preserve compatibility with older versions, see the Older high-level API section.
It offers a higher-level interface than some of the other available modules, and is intended to replace the functions such as os.system(), os.spawn*(), os.popen*(), popen2.() and commands.(). To make it easier to compare the subprocess with those other modules, many of the examples here re-create the ones used for os and popen.
#python #python subprocess