我正在尝试从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终端(app)有一些有趣的地方,但是,我对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,或者如何登录并能够拥有相同的功能呢?
发布于 2012-02-29 20:56:02
使用shell = True
时,subprocess.Popen
的第一个参数应该是字符串,而不是列表:
p = subprocess.Popen('gphoto2', shell=True, ...)
但是,如果可能的话,应该避免使用shell = True
,因为它可以是security risk (参见警告)。
所以请改用
p = subprocess.Popen(['gphoto2'], ...)
(如果为shell = False
,或者如果省略shell
参数,则第一个参数应为列表。)
https://stackoverflow.com/questions/9506437
复制相似问题