Subprocess.Call(ARGs,*,
Stdin = none,Stdout = none,Stderr = none,Shell = false)
In the Internal call function, all parameters cannot be passed.
ClassSubprocess.Popen(ARGs,Bufsize = 0,
Executable = none,Stdin = none,Stdout = none,Stderr = none,
Preexec_fn = none,Close_fds = false,Shell = false,CWD = none,
ENV = none,Universal_newlines = false,Startupinfo = none,Creationflags = 0)
First ParameterARGsIt can be a python sequence or a simple string
Generally, sequence is recommended, because various quotation marks and spaces can be processed, such as escaping arguments.
Providing a sequence of arguments is generallypreferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names ).
However, if shell = true is specified, all parameters must be included in a single string, such as "ls dirname ", otherwise, python will execute/bin/sh-C ls dirname. That is, dirname is changed to the parameter passed to/bin/sh, but not to LS.
IfShellIsTrue, It isrecommended to passARGsAs a string rather than as a sequence.
IfARGsIs a sequence, the first item specifies the command string, andany additional items will be treated as additional arguments to the shellitself. That is to say,Popen
Does the equivalent:
Popen(['/Bin/Sh', '-C', ARGs[0], ARGs[1], ...])
If the command to be executed has a long string of complex parameters, it will be very troublesome to break it into a single sequence element. AvailableShlex. Split ()To complete
In sequence mode, a single element cannot contain spaces.["Ls", "-l"]Yes,["Ls", "-l"]Error!
Note: The above sequence concepts were incorrectly understood in the past two days. There are 7 sequence types in Python, which can be strings or integers.