Python 为什么我总是收到bin/sh:1::找不到

Python 为什么我总是收到bin/sh:1::找不到,python,linux,Python,Linux,我正在学习python编程,并想在linux中尝试一些更改MAC地址的脚本,但我一直遇到以下错误: /bin/sh : 1 : ifconfigeth0down : not found /bin/sh : 1 : ifconfigeth0hw : not found /bin/sh : 1 : ifconfigeth0up : not found 如果有人能帮我,我将不胜感激,谢谢 代码如下: #!/usr/bin/env python import_subprocess interfac

我正在学习python编程,并想在linux中尝试一些更改MAC地址的脚本,但我一直遇到以下错误:

/bin/sh : 1 : ifconfigeth0down : not found
/bin/sh : 1 : ifconfigeth0hw : not found
/bin/sh : 1 : ifconfigeth0up : not found
如果有人能帮我,我将不胜感激,谢谢

代码如下:

#!/usr/bin/env python

import_subprocess

interface = input("interface >")

new_mac = input("new MAC >")

subprocess.call("ifconfig" + interface + "down", shell=True)

subprocess.call("ifconfig + interface + "hw ether" + new_mac, shell=True)

subprocess.call("ifconfig" + interface + "up", shell=True)*

问题是命令的参数周围没有空格

但最好通过传递列表而不是字符串来完全避免shell解析

subprocess.call(["ifconfig", interface, "down"])
supprocess.call(["ifconfig", interface, "hw", "ether", new_mac])
subprocess.call(["ifconfig", interface, "up"])

在ifconfig后面放一个空格,使其成为ifconfig。down也一样,但这次,请将空格放在前面。将命令放在变量中,并在运行之前打印它。这样可以更容易地看出您做错了什么。最好使用列表而不是字符串。的可能重复。也看到