python 子进程调用 OSX

发布于 2024-12-27 08:45:12 字数 1620 浏览 0 评论 0原文

我正在尝试通过 python 访问 wifi 接口: 在bash中我可以使用下面的

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport -I

-s也可以通过。

我尝试在 python 中使用以下内容:

from subprocess import call
call(['/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport', '-I'])

有些东西绝对不正确 - 正如我得到的答复:

Traceback (most recent call last):
  File "ip3.py", line 5, in <module>
    call(['/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport', '-I'])
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/subprocess.py", line 467, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/subprocess.py", line 741, in __init__
    restore_signals, start_new_session)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/subprocess.py", line 1356, in _execute_child
    raise child_exception_type(errno_num, err_msg)
OSError: [Errno 2] No such file or directory: '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport'

欢迎任何想法...我只想开始将其打印到屏幕上,另存为数组等...


我还没有足够高的评分来回答我自己的问题,所以我会在这里说!

所以我很愚蠢!

from subprocess import call
call(['/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport', '-I'])

工作正常。只需删除 /usr/sbin/airport

I am trying to access the wifi interface through python:
In bash I can use the following

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport -I

-s can also be passed.

I have tried using the following in python:

from subprocess import call
call(['/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport', '-I'])

something is definitely not correct - as I get as a reply:

Traceback (most recent call last):
  File "ip3.py", line 5, in <module>
    call(['/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport', '-I'])
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/subprocess.py", line 467, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/subprocess.py", line 741, in __init__
    restore_signals, start_new_session)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/subprocess.py", line 1356, in _execute_child
    raise child_exception_type(errno_num, err_msg)
OSError: [Errno 2] No such file or directory: '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport'

Any ideas would be welcome... I just want to begin by printing this to screen, saving as an array etc...


I dont have a high enough rating to answer my own question yet, so Ill say it here!

so I was being stupid!

from subprocess import call
call(['/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport', '-I'])

Works fine. Just needed to remove /usr/sbin/airport

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心碎的声音 2025-01-03 08:45:12

调用将第一个参数作为命令,并使用该命令的后续参数。

在你的情况下
命令是,
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport

和命令的两个参数是

  1. /usr/sbin/airport
  2. -I

因此,您需要将其称为,

from subprocess import call
call(['/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport' '/usr/sbin/airport', '-I'])

call take first argument as command and subsequent arguments to that command.

In your case
command is,
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport

and command's two arguments are,

  1. /usr/sbin/airport
  2. -I

So, you need to call it as,

from subprocess import call
call(['/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport' '/usr/sbin/airport', '-I'])
哑剧 2025-01-03 08:45:12

尝试这样

from subprocess import call
 call(['/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport', '/usr/sbin/airport', '-I'])

否则它认为 /usr/sbin/airport 是第一个路径的一部分。

Try like this

from subprocess import call
 call(['/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport', '/usr/sbin/airport', '-I'])

Otherwise it thinks /usr/sbin/airport is part of the first path.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文