Recently discovered the Python commands module, looked at the next source, using the Popen package, formed three functions GetStatus (), GetOutput (), Getstatusoutput ()
The source code is as follows:
def getstatus (file): "" " Return output of" Ls-ld <file> "in a string. " "" Import warnings Warnings.warn ("commands.getstatus () is deprecated", deprecationwarning, 2) return GetOutput ( ' Ls-ld ' + mkarg (file) # Get the output from a shell command to a string.# the exit status is ignored; A trailing newline is stripped.# assume the command would work with ' {...;} 2>&1 ' around it. #def getoutput (cmd): "" " Return output (stdout or stderr) of executing cmd in a shell. " "" return Getstatusoutput (cmd) [1]# Ditto but preserving the exit status.# Returns a pair (sts, output) #def getstatusoutput (cm d): "" " Return (status, output) of executing cmd in a shell. " " Import OS pipe = Os.popen (' {' + cmd + ';} 2>&1 ', ' r ') Text = Pipe.read () sts = Pipe.close () if STS is none:sts = 0 if text[-1:] = = ' \ n ': Text = text[:-1] return sts, text
By looking at the above source, we found that the main use is function Getstatusoutput ().
When I call this function, the result of each execution is: ' {' is not an internal or external command, nor is it a running program or batch file.
The suspect is getstatusoutput () in this sentence pipe = Os.popen (' {' + cmd + ';} 2>&1 ', ' R ') has a problem. But think of this is the module provided by the official website, it is not supposed to occur this problem.
Put pipe = Os.popen (' {' + cmd + ';} 2>&1 ', ' r '), modify to pipe = Os.popen (cmd, ' R '), and the result is executed correctly.
Do not know whether pipe = Os.popen (' {' + cmd + ';} 2>&1 ', ' r ') This sentence causes the problem? There is the understanding of the great God to know next
Commands module in Python, execution error: ' {' is not an internal or external command, or a program or batch file that can be run.