我编写了一个脚本来检查 SVN Repo 是否启动并运行,结果基于返回值。
import subprocess
url = " validurl"
def check_svn_status():
subprocess.call(['svn info'+url],shell=True)
def get_status():
subprocess.call('echo $?',shell=True)
def main():
check_svn_status()
get_status()
if __name__ == '__main__':
main()
我面临的问题是,如果我将 url 更改为不存在的东西,我仍然会得到返回值为 0,但如果我要在脚本之外运行它,即转到终端类型svn info wrong url
,然后执行echo $?
我得到的返回值为 1。但我无法在 python 中重新创建它。有什么指导方针吗?
更新后的TraceBack
Traceback (most recent call last):
File "svn_status.py", line 21, in <module>
main()
File "svn_status.py", line 15, in main
check_svn_status()
File "svn_status.py", line 8, in check_svn_status
p = sp.Popen(['svn info'], stdout=sp.PIPE, stderr=sp.PIPE)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1202, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or director
是的