python子流程中的snmpwalk

python子流程中的snmpwalk,python,python-2.7,net-snmp,Python,Python 2.7,Net Snmp,它在我的Bash shell中工作: 但当我试图通过python子流程执行完全相同的命令时: 有什么问题吗?您应该将shell设置为False,或者使用命令snmpwalk-V,这样就不会出现错误list@brm太好了,谢谢。 $ snmpwalk -V NET-SNMP version: 5.7.2.1 In [1]: from subprocess import check_output, STDOUT In [2]: print check_output(["snmpwalk", "-

它在我的Bash shell中工作:

但当我试图通过python子流程执行完全相同的命令时:


有什么问题吗?

您应该将shell设置为False,或者使用命令snmpwalk-V,这样就不会出现错误list@brm太好了,谢谢。
$ snmpwalk -V
NET-SNMP version: 5.7.2.1
In [1]: from subprocess import check_output, STDOUT

In [2]: print check_output(["snmpwalk", "-V"], stderr=STDOUT, shell=True)
---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
<ipython-input-2-9886fda8a591> in <module>()
----> 1 print check_output(["snmpwalk", "-V"], stderr=STDOUT, shell=True)

/usr/lib/python2.7/subprocess.pyc in check_output(*popenargs, **kwargs)
    571         if cmd is None:
    572             cmd = popenargs[0]
--> 573         raise CalledProcessError(retcode, cmd, output=output)
    574     return output
    575 

CalledProcessError: Command '['snmpwalk', '-V']' returned non-zero exit status 1

In [3]: print check_output(["/usr/bin/snmpwalk", "-V"], stderr=STDOUT, shell=True)
---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
<ipython-input-3-25c11cea9013> in <module>()
----> 1 print check_output(["/usr/bin/snmpwalk", "-V"], stderr=STDOUT, shell=True)

/usr/lib/python2.7/subprocess.pyc in check_output(*popenargs, **kwargs)
    571         if cmd is None:
    572             cmd = popenargs[0]
--> 573         raise CalledProcessError(retcode, cmd, output=output)
    574     return output
    575 

CalledProcessError: Command '['/usr/bin/snmpwalk', '-V']' returned non-zero exit status 1