Python gets command line output __python

Source: Internet
Author: User
Using the Windows system, Python 2.7.
Import OS
Command = ' ping www.baidu.com ' #可以直接在命令行中执行的命令 r = Os.popen (command) #执行该命令 info = r.readlines () #读取命令行的输出到一个list for Li NE in info: #按行遍历 line = Line.strip (' \ r \ n ') Print line

------------------------------------------------------//------------------------------------------- os.syst in Python EM () and Os.popen () distinguish python from calling a shell script or calling a system command, there are two ways: Os.system (cmd) or os.popen (CMD), the former return value is the script's exit status code, The return value of the latter is the output of the script during execution. The actual use, depending on the needs of the choice.

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.