请尝试以下示例:
import subprocessproc = subprocess.Popen(['/bin/bash'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)stdout = proc.communicate('ls -lash')print stdout
您必须阅读有关stdin,stdout和stderr的更多信息。看起来不错的演讲:http://www.doughellmann.com/PyMOTW/subprocess/
编辑:
另一个例子:
>>> process = subprocess.Popen(['/bin/bash'], shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE)>>> process.stdin.write('echo it works!n')>>> process.stdout.readline()'it works!n'>>> process.stdin.write('daten')>>> process.stdout.readline()'wto, 13 mar 2012, 17:25:35 CETn'>>>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)