#-*-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"