Executing commands with the subprocess module
The subprocess module enables us to invoke and communicate with Python processes, send data to the input, and receive the output information. Usage of this module is the preferred way to execute and communicate with operating system commands or start programs.
This module allows us to run and manage processes directly from Python. That involves working with stdin standard input, standard output, and return codes.
The simplest way to execute a command or invoke a process with the subprocess module is via the run()
method, which runs a process with different arguments and returns an instance of the completed process. This instance will have attributes of arguments, return code, standard output (stdout), and standard error (stderr):
run(*popenargs, input=None, capture_output=False, timeout=None, check=False, **kwargs)
The previous method gets the popenargs
argument, which contains a tuple containing the command and the arguments...