• <i id='CRgYu'><tr id='CRgYu'><dt id='CRgYu'><q id='CRgYu'><span id='CRgYu'><b id='CRgYu'><form id='CRgYu'><ins id='CRgYu'></ins><ul id='CRgYu'></ul><sub id='CRgYu'></sub></form><legend id='CRgYu'></legend><bdo id='CRgYu'><pre id='CRgYu'><center id='CRgYu'></center></pre></bdo></b><th id='CRgYu'></th></span></q></dt></tr></i><div id='CRgYu'><tfoot id='CRgYu'></tfoot><dl id='CRgYu'><fieldset id='CRgYu'></fieldset></dl></div>

      <small id='CRgYu'></small><noframes id='CRgYu'>

        <bdo id='CRgYu'></bdo><ul id='CRgYu'></ul>
      <legend id='CRgYu'><style id='CRgYu'><dir id='CRgYu'><q id='CRgYu'></q></dir></style></legend>
        <tfoot id='CRgYu'></tfoot>

        Python子进程调用返回“command not found",终端正确执行

        时间:2023-07-21

      1. <legend id='CFxx6'><style id='CFxx6'><dir id='CFxx6'><q id='CFxx6'></q></dir></style></legend>

            <tbody id='CFxx6'></tbody>
            <i id='CFxx6'><tr id='CFxx6'><dt id='CFxx6'><q id='CFxx6'><span id='CFxx6'><b id='CFxx6'><form id='CFxx6'><ins id='CFxx6'></ins><ul id='CFxx6'></ul><sub id='CFxx6'></sub></form><legend id='CFxx6'></legend><bdo id='CFxx6'><pre id='CFxx6'><center id='CFxx6'></center></pre></bdo></b><th id='CFxx6'></th></span></q></dt></tr></i><div id='CFxx6'><tfoot id='CFxx6'></tfoot><dl id='CFxx6'><fieldset id='CFxx6'></fieldset></dl></div>
          1. <tfoot id='CFxx6'></tfoot>

            <small id='CFxx6'></small><noframes id='CFxx6'>

              • <bdo id='CFxx6'></bdo><ul id='CFxx6'></ul>

                  本文介绍了Python子进程调用返回“command not found",终端正确执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试从 python 运行 gphoto2,但是没有成功.它只是返回未找到的命令.gphoto 已正确安装,如终端中的命令可以正常工作.

                  I am trying to run gphoto2 from python but, with no succes. It just returns command not found. gphoto is installed correctly, as in, the commands work fine in Terminal.

                  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 的了解很少.

                  I know that there is something funny about the osx Terminal (app) but, my knowledge on osx is meager.

                  对这个有什么想法吗?

                  编辑

                  更改了我的一些代码,出现其他错误

                  changed some of my code, other errors appear

                  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'

                  using full path '/opt/local/bin/gphoto2'

                  但是如果有人愿意解释使用哪个 shell 或如何登录并能够拥有相同的功能..?

                  but if someone care to explain which shell to use or how to log in and be able to have the same functionality..?

                  推荐答案

                  使用shell = True时,subprocess.Popen的第一个参数应该是字符串,而不是一个列表:

                  When using shell = True, the first argument to subprocess.Popen should be a string, not a list:

                  p = subprocess.Popen('gphoto2', shell=True, ...)
                  

                  但是,如果可能,应避免使用 shell = True,因为它可能是 安全风险(参见警告).

                  However, using shell = True should be avoided if possible since it can be a security risk (see the Warning).

                  所以改用

                  p = subprocess.Popen(['gphoto2'], ...)
                  

                  (当shell = False,或者省略shell参数时,第一个参数应该是一个列表.)

                  (When shell = False, or if the shell parameter is omitted, the first argument should be a list.)

                  这篇关于Python子进程调用返回“command not found",终端正确执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:python子进程通信()块 下一篇:subprocess.Popen.stdout - 实时读取标准输出(再次)

                  相关文章

                    1. <legend id='KpW55'><style id='KpW55'><dir id='KpW55'><q id='KpW55'></q></dir></style></legend>
                      <i id='KpW55'><tr id='KpW55'><dt id='KpW55'><q id='KpW55'><span id='KpW55'><b id='KpW55'><form id='KpW55'><ins id='KpW55'></ins><ul id='KpW55'></ul><sub id='KpW55'></sub></form><legend id='KpW55'></legend><bdo id='KpW55'><pre id='KpW55'><center id='KpW55'></center></pre></bdo></b><th id='KpW55'></th></span></q></dt></tr></i><div id='KpW55'><tfoot id='KpW55'></tfoot><dl id='KpW55'><fieldset id='KpW55'></fieldset></dl></div>
                    2. <small id='KpW55'></small><noframes id='KpW55'>

                      <tfoot id='KpW55'></tfoot>

                        <bdo id='KpW55'></bdo><ul id='KpW55'></ul>