subprocess.check_output() 不提供完整的 iwconfig 输出 [英] subprocess.check_output() not providing full iwconfig output

查看:27
本文介绍了subprocess.check_output() 不提供完整的 iwconfig 输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个 python 程序来显示有关 WiFi 连接的信息,但我遇到了障碍.subprocess.check_output() 没有按照我需要的方式工作.

I am trying to make a python program to display information about the WiFi connection, but I have hit a snag. subprocess.check_output() is not working the way I need it to.

>>>import subprocess
>>>test = subprocess.check_output("iwconfig")

为我提供以下内容:enp9s0 没有无线扩展.

Provides me with the following: enp9s0 no wireless extensions.

virbr0-nic  no wireless extensions.

virbr0    no wireless extensions.

lo        no wireless extensions.

但是当我进入终端并执行相同的命令时,它为我提供了:

But when I go into a terminal and do the same command, it provides me with this:

wlp4s0    IEEE 802.11abgn  ESSID:[Network Name]  
      Mode:Managed  Frequency:5.2 GHz  Access Point: [access point] 
      Bit Rate=81 Mb/s   Tx-Power=14 dBm   
      Retry short limit:7   RTS thr:off   Fragment thr:off
      Power Management:off
      Link Quality=36/70  Signal level=-74 dBm  
      Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
      Tx excessive retries:0  Invalid misc:26   Missed beacon:0

enp9s0    no wireless extensions.

virbr0-nic  no wireless extensions.

virbr0    no wireless extensions.

lo        no wireless extensions.

谁能告诉我如何解决这个问题(我的目标是在我使用 python 运行它时获取我在终端中运行它时获得的所有信息).我尝试查看文档,但我不明白那里所说的一切.提前致谢.

Can anyone tell me how to fix this (my goal is to get all of the information that I get when I run it in the terminal when I use python to run it). I tried looking at the docs, but I do not understand everything said there. Thank you in advance.

推荐答案

部分输出可能会转到 stderr.

Some of the output may be going to stderr.

test = subprocess.check_output("iwconfig", stderr=subprocess.STDOUT)

这篇关于subprocess.check_output() 不提供完整的 iwconfig 输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆