【发布时间】:2012-03-19 08:53:57
【问题描述】:
我正在尝试从 python 运行 gphoto2,但是没有成功。它只是返回未找到的命令。 gphoto 已正确安装,如终端中的命令正常工作。
p = subprocess.Popen(['gphoto2'], shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, executable='/bin/bash')
for line in p.stdout.readlines():
print line
p.wait()
/bin/bash: gphoto2: command not found
我知道 osx 终端(应用程序)有一些有趣的地方,但是我对 osx 的了解很少。
对这个有什么想法吗?
编辑
更改了我的一些代码,出现其他错误
p = subprocess.Popen(['gphoto2'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout:
print line
raise child_exception
OSError: [Errno 2] No such file or directory
编辑
使用完整路径'/opt/local/bin/gphoto2'
但如果有人愿意解释使用哪个 shell 或如何登录并能够拥有相同的功能..?
【问题讨论】:
-
你为什么不使用
subprocess.check_output()或者一次输出整个东西?
标签: python shell terminal subprocess