问题到底是什么?如何使用子进程执行Shell命令?如果是这样,一些简单的伪代码可能看起来像:
import subprocessmyProcess = subprocess.Popen( ['these', 'are', 'for', 'the', 'shell'], stdout=subprocess.PIPE, stderr=subprocess.PIPE )[outStream, errStream] = myProcess.communicate()
outStream)做任何您想做的事情,并且在
errStream存在标准错误的情况下做其他事情。这包括将标准输出或标准错误写入文件。那我想你会比较那些文件吗?
一个实际的代码示例(假设您在Linux系统上具有python 2.6+)可能看起来像:
import subprocesswith open('dateHelp.log', 'w') as dateLog: with open('dateHelp.err', 'w') as errLog: dateHelp = subprocess.Popen([ 'date', '-h'], stdout=dateLog, stderr=errLog) dateHelp.communicate()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)