python中的subprocess.call退出代码
我有一个通过python子流程执行java jar的用例。我如何知道子流程是否成功完成或因某些异常而终止。子流程确实返回退出代码,但jar不处理返回适当的退出代码。 还有别的办法吗python中的subprocess.call退出代码,python,python-2.7,jar,subprocess,Python,Python 2.7,Jar,Subprocess,我有一个通过python子流程执行java jar的用例。我如何知道子流程是否成功完成或因某些异常而终止。子流程确实返回退出代码,但jar不处理返回适当的退出代码。 还有别的办法吗 class Test(object): #constructor . . def execute(self): exit_code = subprocess.call(['jar_path']) if not exit_code:
class Test(object):
#constructor
.
.
def execute(self):
exit_code = subprocess.call(['jar_path'])
if not exit_code:
return True
else:
return False
既然你说-
问题:jar是否向stdout或stderr报告了正确的异常
答:是的,它确实支持 您可以与和
subprocess.PIPE一起使用
范例-
def execute(self):
proc = subprocess.Popen(['jar_path'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
pout,perr = proc.communicate()
if not perr: #or however you want to check stderr/stdout
return True
else:
return False
既然你说-
问题:jar是否向stdout或stderr报告了正确的异常
答:是的,它确实支持
您可以与和subprocess.PIPE一起使用
范例-
def execute(self):
proc = subprocess.Popen(['jar_path'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
pout,perr = proc.communicate()
if not perr: #or however you want to check stderr/stdout
return True
else:
return False
既然你说-
问题:jar是否向stdout或stderr报告了正确的异常
答:是的,它确实支持
您可以与和subprocess.PIPE一起使用
范例-
def execute(self):
proc = subprocess.Popen(['jar_path'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
pout,perr = proc.communicate()
if not perr: #or however you want to check stderr/stdout
return True
else:
return False
既然你说-
问题:jar是否向stdout或stderr报告了正确的异常
答:是的,它确实支持
您可以与和subprocess.PIPE一起使用
范例-
def execute(self):
proc = subprocess.Popen(['jar_path'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
pout,perr = proc.communicate()
if not perr: #or however you want to check stderr/stdout
return True
else:
return False
jar是否向stdout或stderr报告了正确的异常?是的,它支持。jar是否向stdout或stderr报告了正确的异常?是的,它支持。jar是否向stdout或stderr报告了正确的异常?是的,它支持。它是否会生成子流程非阻塞如果我使用Popen而不是call?嗯,.communicate()
正在阻塞,它将阻塞进程,直到过程完成。我尝试了使用communicate。stderr和stdout输出都被重定向到文件而不是管道。可能是因为pout和perr看起来没有。当您在命令行中直接运行jar文件时,控制台中有输出吗?是的,我有。但现在在Popen中,我使用文件转储stdout和stderr结果。我正在将这些日志记录到一个文件中。但pout和perr似乎是无效的。是因为我将输出重定向到一个文件而不是管道吗?如果我使用Popen而不是call,会不会使子进程不阻塞?嗯,.communicate()
正在阻塞,它将阻塞进程,直到过程完成。我尝试了使用communicate。stderr和stdout输出都被重定向到文件而不是管道。可能是因为pout和perr看起来没有。当您在命令行中直接运行jar文件时,控制台中有输出吗?是的,我有。但现在在Popen中,我使用文件转储stdout和stderr结果。我正在将这些日志记录到一个文件中。但pout和perr似乎是无效的。是因为我将输出重定向到一个文件而不是管道吗?如果我使用Popen而不是call,会不会使子进程不阻塞?嗯,.communicate()
正在阻塞,它将阻塞进程,直到过程完成。我尝试了使用communicate。stderr和stdout输出都被重定向到文件而不是管道。可能是因为pout和perr看起来没有。当您在命令行中直接运行jar文件时,控制台中有输出吗?是的,我有。但现在在Popen中,我使用文件转储stdout和stderr结果。我正在将这些日志记录到一个文件中。但pout和perr似乎是无效的。是因为我将输出重定向到一个文件而不是管道吗?如果我使用Popen而不是call,会不会使子进程不阻塞?嗯,.communicate()
正在阻塞,它将阻塞进程,直到过程完成。我尝试了使用communicate。stderr和stdout输出都被重定向到文件而不是管道。可能是因为pout和perr看起来没有。当您在命令行中直接运行jar文件时,控制台中有输出吗?是的,我有。但现在在Popen中,我使用文件转储stdout和stderr结果。我正在将这些日志记录到一个文件中。但pout和perr似乎是无效的。是否因为我将输出重定向到文件而不是管道?