Commands module does not support Windows environment, let's take a look.
To view the source code for Commands.getoutput:
def getoutput (cmd): "" " Return output (stdout or stderr) of executing cmd in a shell. " "" return Getstatusoutput (CMD) [1]
This function calls the Commands.getstatusoutput () function, which looks at the source code of the next Commands.getstatusoutput
defgetstatusoutput (cmd):"""Return (status, output) of executing cmd in a shell.""" ImportOS pipe= Os.popen ('{ '+ cmd +'; } 2>&1','R') Text=pipe.read () STS=pipe.close ()ifSts isNone:sts =0ifText[-1:] = ='\ n': Text = text[:-1] returnSTS, text
As you can see from the Commands.getstatusoutput code, the command is changed to ' {' + cmd + ';} 2>&1 ', which is a command run under Linux, Windows does not support.
Therefore, the commands module does not support the Windows environment.
So how do you make it support the Windows environment?
My advice:
1, create a new module, copy commands content into which
2. Change the ' {' + cmd + ';} 2>&1 ' to cmd under the Getstatusoutput function
Of course the Getstatushan function still has problems, if you want to use, please refer to the Windows environment to modify.
Summary, the above is a bit of my experience, if there is a problem, please contact me.
Python commands package does not support the Windows environment and how to use it in Windows easy way