在MAC上使用python的subprocess模块的问题?

import subprocess

def killpid():
    cmd = ["adb", "shell", "ps"]
    # print cmd
    run_cmd = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    print run_cmd.stdout.read()
    
if __name__ == '__main__':
    killpid()

运行结果提示:

['adb', 'shell', 'ps']
Traceback (most recent call last):
  File "/Users/***/test1.py", line 30, in <module>
    killpid()
  File "/Users/***/test1.py", line 11, in killpid
    run_cmd = subprocess.Popen(cmd, stdout=subprocess.PIPE)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
[Finished in 0.049s]

这段代码在Windows上运行没有问题,但在MAC上就报错。

阅读 10.1k
1 个回答
sp = subprocess.Popen(["ls", "-l"])

Return to the fucking manual.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏