Python module subprocess

Source: Internet
Author: User
Tags stdin

Common usage of subprocess

1 """2 Description:3 Author:nod4 Date:5 Record:6 #---------------------------------v1-----------------------------------#7 """8 9 ImportsubprocessTen Import Time One  A #the correct command is output through the pipeline -obj = subprocess. Popen ('Ping 127.0.0.1', shell=True, -stdout=subprocess. PIPE, theStderr=subprocess. PIPE, -                        ) - Print('\033[31;1m Execution Results 1\033[0m') - Print(Obj.stdout.read (). Decode ('GBK')) +  - #incorrect command output through the pipeline +obj = subprocess. Popen ('12ping 127.0.0.1', shell=True, Astdout=subprocess. PIPE, atStderr=subprocess. PIPE, -  -                        ) - Print('\033[31;1m Execution Results 2\033[0m') - Print(Obj.stderr.read (). Decode ('GBK')) -  in #how to execute a sequence of commands 1 tasklist | findstr python -obj =subprocess. Popen ( to     'tasklist | findstr python', shell=True, +Stdout=subprocess. PIPE,#the correct result of the command enters the pipeline -Stderr=subprocess. PIPE,#Command error results into 1 additional pipelines the  * ) $ Print('\033[31;1m Execution Results 3\033[0m')Panax Notoginseng Print(Obj.stdout.read (). Decode ('GBK')) -  the #how to execute a sequence of commands 2 +Obj2 =subprocess. Popen ( A     'tasklist', shell=True, thestdout=subprocess. PIPE, +Stderr=subprocess. PIPE, - ) $ #The results of obj2 execution are entered here to Obj2 Stdin=obj2.stdout, $Obj3 =subprocess. Popen ( -     'findstr python', -Shell=True, thestdin=Obj2.stdout, -stdout=subprocess. PIPE,WuyiStderr=subprocess. PIPE, the ) - Print('\033[31;1m Execution Results 4\033[0m') Wu Print(Obj3.stdout.read (). Decode ('Utf-8'))
View Code

Python module subprocess

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.