我有一个用于执行外部进程的小实用程序功能。在某些情况下,当我尝试读取进程的输出时它会挂起。注释掉输出阅读行,它可以工作。
def execute(command, cwd):
command = command.split(' ')
process = Popen(command,
stderr=STDOUT, stdout=PIPE,
cwd = cwd)
# WITHOUT THIS IT WORKS
#for line in process.stdout:
# log.info('executing %s for user %s: %s' % (command, user.username, line))
# ANOTHER TRY AT READING THE OUTPUT. ALSO MAKES IT HANG
#output = p.communicate()[0]
#log.info('executing %s for user %s: %s' % (command, user.username, output))
process.wait()
有什么帮助吗?我需要输出以进行调试。