Running and spawning a new system process can be useful to system administrators who want to automate specific operating system tasks or execute a few commands within their scripts. Python provides many libraries to call external system utilities, and it interacts with the data produced. The first library that was created is the OS module, which provides some useful tools to invoke external processes, such as os.system, os.spwan, and os.popen*. It lacks some essential functions, however, so Python developers have introduced a new library, subprocess, which can spawn new processes, send and receive from the processes, and handle error and return codes. Currently, the official Python documentation recommends the subprocess module for accessing system commands, and Python actually intends to replace the older modules with it.
The following topics will...