Und*_*ior 2 windows subprocess cmd exit-code python-3.x
python中的这段脚本:
cmd = 'installer.exe --install ...' #this works fine, the ... just represent many arguments
process = subprocess.Popen(cmd)
process.wait()
print(process.returncode)
Run Code Online (Sandbox Code Playgroud)
这段代码在我看来运作正常,问题在于价值.returncode.
installer.exe没问题,做了很多测试,现在我尝试在python中创建一个脚本,以便在执行此installer.exe的许多天内自动执行测试.
installer.exe返回: - 成功为0; - 失败和错误是负数
我有一个特定的错误,即installer.exe返回-307.但是python在执行print(process.returncode)它时会显示4294966989 ...我如何在python中处理负数,在这种情况下显示-307?
我是python的新手,env是win7 32和python 3.4.
编辑:最终的代码工作 此代码的部分是运行许多简单的测试:
import subprocess, ctypes, datetime, time
nIndex = 0
while 1==1:
cmd = 'installer.exe --reinstall -n "THING NAME"'
process = subprocess.Popen( cmd, stdout=subprocess.PIPE )
now = datetime.datetime.now()
ret = ctypes.c_int32( process.wait() ).value
nIndex = nIndex + 1
output = str( now ) + ' - ' + str( nIndex ) + ' - ' + 'Ret: ' + str( ret ) + '\n'
f = open( 'test_result.txt', 'a+' )
f.write( output )
f.closed
print( output )
Run Code Online (Sandbox Code Playgroud)
仅使用标准库:
>>> import struct
>>> struct.unpack('i', struct.pack('I', 4294966989))
(-307,)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1387 次 |
| 最近记录: |