我想通过python运行一个长进程(calculix模拟)。
正如前面提到的,here可以使用communicate()读取控制台字符串。
据我所知,字符串是在进程完成后返回的?是否有可能在进程运行时获得控制台输出?
发布于 2014-04-04 10:26:35
您必须使用subprocess.Popen.poll来检查进程终止与否。
while sub_process.poll() is None:
output_line = sub_process.stdout.readline()这将为您提供运行时输出。
发布于 2014-04-04 10:21:30
这应该是可行的:
sp = subprocess.Popen([your args], stdout=subprocess.PIPE)
while sp.poll() is None: # sp.poll() returns None while subprocess is running
output = sp.stdout # here you have acccess to the stdout while the process is running
# Do stuff with stdout请注意,这里没有在子进程上调用communicate()。
https://stackoverflow.com/questions/22859662
复制相似问题