gpt4 book ai didi

python - 为什么我一直收到 bin/sh : 1 : : not found

转载 作者:太空宇宙 更新时间:2023-11-04 11:55:41 25 4
gpt4 key购买 nike

我正在学习 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"])

关于python - 为什么我一直收到 bin/sh : 1 : : not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54429853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com