python subprocess.Popen异常示例的一些示例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python subprocess.Popen异常示例的一些示例相关的知识,希望对你有一定的参考价值。
#!/usr/bin/python
import subprocess
import os
import sys
#res = subprocess.Popen(['ls','-al','/ahome'],stdout=subprocess.PIPE,stderr=subprocess.PIPE);
#output,error = res.communicate()
#if res.returncode:
# #raise Exception(error)
# print "error>>>> ",res.returncode
#else:
# print "output>>>> ",output
try:
res = subprocess.Popen(['ls','-al','/home'],stdout=subprocess.PIPE,stderr=subprocess.PIPE);
#res = subprocess.Popen(['xls','-al','/home'],stdout=subprocess.PIPE);
output,error = res.communicate()
if output:
print "ret> ",res.returncode
print "OK> output ",output
if error:
print "ret> ",res.returncode
print "Error> error ",error.strip()
#except CalledProcessError as e:
# print "CalledError > ",e.returncode
# print "CalledError > ",e.output
except OSError as e:
print "OSError > ",e.errno
print "OSError > ",e.strerror
print "OSError > ",e.filename
except:
print "Error > ",sys.exc_info()[0]
以上是关于python subprocess.Popen异常示例的一些示例的主要内容,如果未能解决你的问题,请参考以下文章
python subprocess.popen stdin.write
python subprocess.Popen
python中的subprocess.Popen()使用
Python subprocess.Popen PIPE和SIGPIPE
杀死使用 Python 的 subprocess.Popen() 创建的进程 [重复]
python中的subprocess.Popen | 9