python返回负数_如何处理返回码从Python中的subprocess负数?

This piece of script in python:

cmd = 'installer.exe --install ...' #this works fine, the ... just represent many arguments

process = subprocess.Popen(cmd)

process.wait()

print(process.returncode)

This code works fine in my opinion, the problem is the value of .returncode.

The installer.exe is ok, did many test to this, and now i trying to create a script in python to automate a test for many days executing this installer.exe .

The installer.exe return:

- Success is 0;

- Failure and errors are NEGATIVE numbers

I have a specific error that is -307 that installer.exe return. But python when execute print(process.returncode) its shows 4294966989 ... How can i deal with negative numbers in python, to show in this case the -307?

I am new to python and the env is win7 32 and python 3.4.

EDIT: the final code working

The porpose of this code is to run many simple test:

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 )

解决方案

Using NumPy: view the unsigned 32-bit int, 4294966989, as a signed 32-bit int:

In [39]: np.uint32(4294966989).view('int32')

Out[39]: -307

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值