subprocess.Popen returncode
#1
Hi Guys,

Just a little question. The code below should give me an error code. But it doesn't. It alwas comes with a 0, even if I change the IP address to one that doesn't exist on the network. Why is that?

I also tried ping.returncode. But nothing seems to work.

Code:
import subprocess
    ping = subprocess.Popen(["ping", "-c", "1", "10.0.0.123"])
    return_code = ping.wait()
    print return_code

Did I make a typo? Or is there an other way around this?

Thanks
moh-san
Reply
#2
what platform are you testing this on? is it windows?

I think it is a problem with the platforms ping program that doesn't return status codes correctly.

I found a reference to the same problem here I believe. http://mail.python.org/pipermail/tutor/2...87959.html

maybe you could work around it with communicate() instead of wait().
Reply
#3
Hi BlueCop,

Thank you for your reply. I'm working with XBMCbuntu. It is a new installation on a Zotac zbox ID41. Also, I tested my addon with a Zotac zbox ID80 same problem Confused . It seems that this is a issue with the hardware or drivers. Because I've setup a virtual machine with VirtualBox and everything works like it should. Using the same USB stick to install XBMCbuntu on all boxes, using the same settings (there are almost none) and copy my addon to the addon directory, that's it.

Are there more people having this problem?

Thanks
moh-san
Reply
#4
Ok, I gave up on the returncode, errorcode thing.
What a did is, show the last message and pickout words.

Code:
ping = subprocess.Popen(["ping", "-c", "1", "10.0.0.123"], stdout=subprocess.PIPE, stderr = subprocess.PIPE)
    ping_out, ping_err = ping.communicate()
    if "1 received" in ping_out:
        print "Server IP OK.."

So thanks BlueCop for pointing me in the right direction!

moh-san
Reply

Logout Mark Read Team Forum Stats Members Help
subprocess.Popen returncode0