Python commands package does not support the Windows environment and how to use it in Windows easy way

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.