Python: Check existence of shell command before execution

Posted by Gabriel L. Oliveira on Super User See other posts from Super User or by Gabriel L. Oliveira
Published on 2010-06-04T15:47:56Z Indexed on 2010/12/21 15:56 UTC
Read the original article Hit count: 337

Filed under:
|
|
|

Hi all. I'm trying to find a way to check the existence of a shell command before its execution.

For example, I'll execute the command ack-grep. So, I'm trying to do:

import subprocess
from subprocess import PIPE

cmd_grep = subprocess.Popen(["ack-grep", "--no-color", "--max-count=1", "--no-group", "def run_main", "../cgedit/"], stdout=PIPE, stderr=PIPE)

Than, if I execute

cmd_grep.stderr.read()

I receive '' like the output. But I don't have the command ack-grep on my path. So, why Popen is not putting the error message on my .stderr variable?

Also, is there a easyer way to do what I'm trying to do?

© Super User or respective owner

Related posts about shell

Related posts about process