I am attempting to use subprocess.check_call()
and netsh in order to change my computer's NIC card settings. Currently using python 2.7 and Windows7.
This command is successful when I run it in from cmd.exe:
netsh interface ip set address name="Local Area Connection" static 192.168.1.1 255.255.255.0 192.168.1.2
This python script is not successful:
import subprocess
command = ['netsh','interface','ip','set','address','name="Local Area Connection"','static','192.168.1.1','255.255.255.0','192.168.1.2']
result = subprocess.check_call(command)
And this is the last line of the traceback output given from the python script above:
CalledProcessError: Command '['netsh', 'interface', 'ip', 'set', 'address', 'name="Local Area Connection"', 'static', '192.168.1.1', '255.255.255.0', '192.168.1.2']' returned non-zero exit status 1
So, something is obviously going wrong and I am trying to track down what. The first thing I would like to resolve is what the returncodes mean? I hope I'm not being dense, but https://python.readthedocs.org/en/v2.7.2/library/subprocess.html# doesn't seem to explain what the returncode actually means. I did find this thread, What is the return value of subprocess.call()?, but it only gives blanket statements about return codes in general. Would anybody know how to figure out the meaning of return codes specific to subprocess.check_call()
?
That would help me get a start at troubleshooting, but if anybody has any ideas as to why the script is failing in the first place, that would be greatly appreciated. I have tried using "Run as administrator" to open cmd.exe, and then running the python script from there, but the result is the same. This thread seems to be the same issue but I don't see a resolution to it:
Using subprocess.call() to pass commands to execute by cmd. I have tried setting command = netsh interface ip set address name="Local Area Connection" static 192.168.1.1 255.255.255.0 192.168.1.2
and subprocess.check_call(command,shell=True)
as well as subprocess.check_call(shlex.split(command))
, and both return code '1'.