Python子进程stdout and communicate()[0]不打印终端将

2024-04-27 03:17:37 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码。

import subprocess

bashCommand = "./program -s file_to_read.txt | ./awk_program.txt"
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
output2 = process.stdout
print output
print output2

这个bash命令在终端中单独使用时打印awk_程序的输出(它只打印到stdout)。但是在python中,output什么都不打印,output2打印

<closed file '<fdopen>', mode 'rb' at 0x2b5b20>

我需要做什么才能返回输出?


Tags: toimporttxt密码readoutputstdoutprogram