我想检查子进程是否已成功执行或失败.目前我已经提出了一个解决方案,但我不确定它是否正确可靠.是否保证每个进程仅向stderr输出其错误stdout:
注意:我对重定向/打印输出不感兴趣.我知道该怎么做.
pipe = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
if "" == pipe.stdout.readline():
print("Success")
self.isCommandExectutionSuccessful = True
if not "" == pipe.stderr.readline():
print("Error")
self.isCommandExectutionSuccessful = True
Run Code Online (Sandbox Code Playgroud)
或者:
if "" == pipe.stdout.readline():
print("Success")
self.isCommandExectutionSuccessful = True
else:
print("Error")
self.isCommandExectutionSuccessful = False
Run Code Online (Sandbox Code Playgroud)
和:
if not "" == pipe.stderr.readline():
print("Success")
self.isCommandExectutionSuccessful = True
else:
print("Error")
self.isCommandExectutionSuccessful = False
Run Code Online (Sandbox Code Playgroud) 我创建了一个在命令行上打印结果的程序.(它是服务器,它在命令行上打印日志.)
现在,我希望看到与GUI相同的结果.
如何将命令行结果重定向到GUI?
请提出一个技巧,以便轻松将控制台应用程序转换为简单的GUI.
请注意,它应该适用于Linux和Windows.