标签:ror 属性 universal dir 创建 sed 系统 rsa comm
subprocess的目的就是启动一个新的进程并且与之通信。
subprocess模块中只定义了一个类: Popen。可以使用Popen来创建进程,并与进程进行复杂的交互。
subprocess.Popen(...)
用于执行复杂的系统命令
参数:
import subprocess ret1 = subprocess.Popen(["mkdir","t1"]) ret2 = subprocess.Popen("mkdir t2", shell=True)
终端输入的命令分为两种:
import subprocess obj = subprocess.Popen("mkdir t3", shell=True, cwd=‘/home/dev‘,)
import subprocess obj = subprocess.Popen(["python"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) obj.stdin.write(‘print 1 \n ‘) obj.stdin.write(‘print 2 \n ‘) obj.stdin.write(‘print 3 \n ‘) obj.stdin.write(‘print 4 \n ‘) obj.stdin.close() cmd_out = obj.stdout.read() obj.stdout.close() cmd_error = obj.stderr.read() obj.stderr.close() print cmd_out print cmd_error
import subprocess obj = subprocess.Popen(["python"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) obj.stdin.write(‘print 1 \n ‘) obj.stdin.write(‘print 2 \n ‘) obj.stdin.write(‘print 3 \n ‘) obj.stdin.write(‘print 4 \n ‘) out_error_list = obj.communicate() print out_error_list
import subprocess obj = subprocess.Popen(["python"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out_error_list = obj.communicate(‘print "hello"‘) print out_error_list
标签:ror 属性 universal dir 创建 sed 系统 rsa comm
原文地址:http://www.cnblogs.com/PyLearning/p/6407324.html