我试图从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或者如何登录并能够拥有相同的功能。。?
使用
shell = True
时,subprocess.Popen
的第一个参数应该是字符串,而不是列表:但是,如果可能的话,应该避免使用
shell = True
,因为它可以是security risk(参见警告)。所以用
(当
shell = False
,或者如果省略了shell
参数,则第一个参数应该是一个列表。)相关问题 更多 >
编程相关推荐