DreamCatch DreamCatch - 1 year ago 121
Python Question

Python subprocess Popen

Why its not working? :|

import subprocess
p = subprocess.Popen([r"snmpget","-v","1","-c","public","-Oqv","","-Ln",""],stdout=subprocess.PIPE).communicate()[0]
print p

Run script:

root@OpenWrt:~/python# python w.py


its printing empty line :|
Bu on the same machine, from shell:

root@OpenWrt:~/python# snmpget -v 1 -c public -Oqv -Ln

I know tere is "-Oqv","", but without it i got error from snmpget...

Answer Source

I see you have an empty string in your args:

... ,"-Oqv","","-Ln", ...

Is that possibly causing a problem for snmpget?

You've got two arguments in one, too:


That should be split in two:

"", ""

When typing a command on the command line, the shell does this splitting for you. When calling subprocess.Popen() in this way, you'll have to do all the argument splitting yourself. You'd get the same error if you ran:

snmpget -v 1 -c public -Oqv -Ln ''
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download