Python subprocess returns "command not found", the terminal is executed correctly

I am trying to run gphoto2 from python, but without any success. It just returns a command not found. gphoto is installed correctly, as in, the commands work fine in the 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 

I know that there is something funny in the osx terminal (application), but my knowledge of osx is scarce.

Any thoughts on this?

EDIT

changed part of my code, other errors appeared

 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 

EDIT

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

but if someone wants to explain which shell to use or how to enter the system and have the same functionality.?

+7
source share
1 answer

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

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

However, using shell = True should be avoided if possible, as this may be a security risk (see warning).

So use instead

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

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

+7
source

All Articles