我使用这个小实用程序函数来执行外部进程。在某些情况下,当我尝试读取进程的输出时,它会挂起。评论输出读数线,它可以工作。
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()
有任何帮助吗?我需要输出以进行调试。