[英]linux command is not working in python subprocess
I am trying to scan all available wifi devices using python. 我正在尝试使用python扫描所有可用的wifi设备。 I wrote below code to get SSID,BSSID and device information
我写了下面的代码来获取SSID,BSSID和设备信息
results = subprocess.check_output(["sudo", "nmcli", "-f", "SSID", "BSSID", "DEVICE", "dev", "wifi"])
But it is giving me error- "bssid not understood" 但这给了我错误-“ bssid无法理解”
when I run the below command in terminal it is working fine. 当我在终端中运行以下命令时,它工作正常。
sudo nmcli -f SSID,BSSID,DEVICE dev wifi
If I remove BSSID and DEVICE then it is working fine. 如果我删除了BSSID和DEVICE,则工作正常。 And I am getting all the ssids
我得到所有的ssids
results = subprocess.check_output(["sudo", "nmcli", "-f", "SSID", "dev", "wifi"])
I could not understand what is going wrong. 我不明白怎么了。
I am using 我在用
Python-3.6.8
Ubuntu-18.04.2 LTS
you need to pass the arguments as 您需要将参数传递为
["sudo", "nmcli", "-f", "SSID,BSSID,DEVICE", "dev", "wifi"]
if the last command line really works. 如果最后一个命令行确实有效。 note that there is one argument
"SSID,BSSID,DEVICE"
. 请注意,只有一个参数
"SSID,BSSID,DEVICE"
。
you could also generate the list using shlex
: 您还可以使用
shlex
生成列表:
import shlex
args = shlex.split("sudo nmcli -f SSID,BSSID,DEVICE dev wifi")
# ['sudo', 'nmcli', '-f', 'SSID,BSSID,DEVICE', 'dev', 'wifi']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.