【发布时间】:2015-03-16 07:15:57
【问题描述】:
以下代码不会写入我正在创建的日志文件 (Dm_Log.txt)。但是,如果我注释掉 stdout,stderr = process.communicate() 那么它确实如此。如果我不使用通信,子进程会停止,因为我正在执行 process.wait()。如何解决这个问题?我也需要写入日志文件并运行该过程。
logfilePath = self.psexeclogs + 'Dm_Log.txt'
logfile = file(logfilePath,'w')
try:
process = subprocess.Popen(drivemaster_open_command, stdout = subprocess.PIPE,stderr = subprocess.PIPE)
stdout, stderr = process.communicate()
for line in process.stderr:
print ' '
sys.stderr.write(line)
logfile.write(line)
process.wait()
except OSError:
print "********COULD NOT FIND PSEXEC.EXE, PLEASE REINSTALL AND SET THE PATH VARIABLE PROPERLY********\n"
#Close the logfile first
logfile.close()
【问题讨论】:
标签: python python-2.7 python-3.x