错误讯息:
Failed to open output_file_path/**.txt
代码:
cmd = 'showTxt "%s" > "%s"' % (file_path, output_file_path)
LoggerInstance.log('[cmd] '+cmd)
#os.system(cmd)
splited_cmd=shlex.split(cmd)
p = subprocess.Popen(splited_cmd, stderr=subprocess.PIPE)
#p.wait()
output = p.stderr.read()
print output
LoggerInstance.log('[console std error]'+ output)
如何将stdout重定向到cmd中的文件?
答案 0 :(得分:2)
您可以向file-handler
提供stdout
Popen
参数,即:
p = subprocess.Popen(splited_cmd,
stderr=subprocess.PIPE,
stdout=open(output_file_path, "w"))
当然,准备好捕捉它可以抛出的异常。