Themodule allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several older modules and functions:
os.system
os.spawn*
The recommended approach to invoking subprocesses is to use thefunction for all use cases it can handle. For more advanced use cases, the underlyingintece can be used directly.
Thefunction was added in Python 3.5; if you need to retain compatibility with older versions, see thesection.
subprocess.run(args, *, stdin=None, input=None, stdout=None, stderr=None, shell=False, timeout=None, check=False)
Run the command described byargs. Wait for command to complete, then return ainstance.
The arguments shown above are merely the most common ones, described below in(hence the use of keyword-only notation in the abbreviated signature). The full function signature is largely the same as that of theconstructor - apart fromtimeout,inputandcheck, all the arguments to this function are passed through to that intece.
This does not capture stdout or stderr by default. To do so, passfor thestdoutand/orstderrarguments.
Thetimeoutargument is passed to. If the timeout expires, the child process will be killed and waited for. Theexception will be re-raised after the child process has terminated.
Theinputargument is passed toand thus to the subprocess’s stdin. If used it must be a byte sequence, or a string ifuniversal_newlines=True. When used, the internalobject is automatically created withstdin=PIPE, and thestdinargument may not be used as well.
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-49678-1.html
三是武器落后