获取线程的命令行输出

我有一个主要脚本,它按某种顺序运行其他几个程序(以避免手动启动它们)。因此,我使用线程来调用它们。 第一个是Windows应用程序,我这样称呼它:

class Nepthread(threading.Thread):
    def run(self):
        subprocess.call('PATH_TO_PRGM.exe')
        pass
#...
nepthread = Nepthread()
nepthread.daemon = True
nepthread.start()

然后我以相同的方式运行Python脚本:

class UsbCameraThread(threading.Thread):
    def run(self):
        subprocess.call(["python",'PATH\\USBcamera.py'])
        pass
#...
usbCameraThread = UsbCameraThread()
usbCameraThread.daemon = True
usbCameraThread.start()

但是对于这个,我需要等待它启动之后再运行下一个脚本。 当USBcamera脚本准备就绪时,它将在cout上写一些东西,然后开始无限循环:

print('Start Video recording!')
while True:

我的问题是:如何获取命令行输出以了解脚本是否已启动?

提前谢谢! 黑暗之味

qq872167458 回答:获取线程的命令行输出

您可能可以使用subprocess.Popen()指令捕获标准输出流。这是其用法示例:

proc = subprocess.Popen( command,stdout = subprocess.PIPE,stderr = subprocess.PIPE )
stdout_stream,stderr_stream = proc.communicate()
stdout_stream = stdout_stream.decode( "ascii" )

然后打印出stdout_stream的内容。

本文链接:https://www.f2er.com/3147257.html

大家都在问