Python subprocess Execute system command pipeline, read result "multi-process, interprocess pipeline communication"

Source: Internet
Author: User
Tags stdin python subprocess

#-*-Coding:utf-8-*-__author__ = ' magicpwn ' import subprocessimport sysreload (SYS) sys.setdefaultencoding (' Utf-8 ') # Two functions to execute the command, new Process Execution system command s = Subprocess.check_call (' dir ', shell=true) p = subprocess.call (' dir ', shell=true) print S, p# Execute command and Capture system command output result = Subprocess.check_output (' Netstat-an ', shell=true) # Direct call Popen set to process bidirectional communication, pipeline communication proc = subprocess. Popen ([' netstat ', '-an '], stdin=subprocess. PIPE, Stdout=subprocess. PIPE) msg = ' through stdin to stdout ' Stdout_value = proc.communicate (msg) [0]print ' \tpass through: ', repr (Stdout_value)


This article is from the "Magicpwn" blog, make sure to keep this source http://magicpwn.blog.51cto.com/10497784/1682429

Python subprocess executes the system command pipeline, reads the result "multi-process, inter-process pipeline communication"

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.