Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #101013

Re: subprocess check_output

From Cameron Simpson <cs@zip.com.au>
Newsgroups comp.lang.python
Subject Re: subprocess check_output
Date 2015-12-31 08:02 +1100
Message-ID <mailman.86.1451509358.11925.python-list@python.org> (permalink)
References <CAJYwLU=p_U3V7MfOx3wCH8qkamK0aSHzF1i0g2ZBgTXDgrF03Q@mail.gmail.com>

Show all headers | View raw


On 30Dec2015 21:14, Carlos Barera <carlos.barera@gmail.com> wrote:
>Trying to run a specific command (ibstat)  installed in /usr/sbin on an
>Ubuntu 15.04 machine, using subprocess.check_output and getting "/bin/sh:
>/usr/sbin/ibstat: No such file or directory"
>
>I tried the following:
>- running the command providing full path
>- running with executable=bash
>- running with (['/bin/bash', '-c' , "/usr/sbin/ibstat"])
>
>Nothing worked ...

The first check is to run the command from a shell. Does it work? Does "which 
ibstat" confirm that the command exist at that path? Is it even installed?

If it does, you should be able to run it directly without using a shell:

  subprocess.call(['/usr/sbin/ibstat'], ...)

or just plain ['ibstat']. Also remember that using "sh -c blah" or "bash -c 
blah" is subject to all the same security issues that subprocess' "shell=True" 
parameter is, and that it should be avoided without special reason.

Finally, remember to drop the common Linux fetish with "bash". Just use "sh"; 
on many systems it _is_ bash, but it will provide portable use. The bash is 
just a partiular Bourne style shell, not installed everywhere, and rarely of 
any special benefit for scripts over the system /bin/sh (which _every_ UNIX 
system has).

If none of this solves your problem, please reply including the failing code 
and a transcript of the failure output.

Thanks,
Cameron Simpson <cs@zip.com.au>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: subprocess check_output Cameron Simpson <cs@zip.com.au> - 2015-12-31 08:02 +1100

csiph-web