KhAn Tsai
KhAn Tsai

Reputation: 3

python exit code from subprocess

I have one python content as below, and why I got ipmitool completion code is 00, but always return "failed"?

import subprocess
def sdr(hostname,username,password):
    IPMI_SERVER=hostname
    IPMI_USERNAME=username
    IPMI_PASSWORD=password
    p = subprocess.run(["ipmitool.exe", "-H", IPMI_SERVER, "-U", IPMI_USERNAME, "-P", IPMI_PASSWORD, "-I", "lanplus", "raw", "0x06","0x01"], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    #p = subprocess.run(["ipmitool.exe -H 192.168.2.140 -I lanplus -U admin -P admin sdr elist full"], stdout=subprocess.PIPE)
    output= p.returncode
    return output

if sdr("192.168.2.140","admin","admin"):
    print ("successfully")
else:
    print ("failed")

Upvotes: 0

Views: 639

Answers (1)

Edwin van Mierlo
Edwin van Mierlo

Reputation: 2488

The p.returncode is an int, so if it is successful it will be 0, which is False in your if statement, therefore it will execute print("failed")

Upvotes: 1

Related Questions