Using the Subprocess Module

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 ...

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.