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


Groups > comp.lang.python > #101013 > unrolled thread

Re: subprocess check_output

Started byCameron Simpson <cs@zip.com.au>
First post2015-12-31 08:02 +1100
Last post2015-12-31 08:02 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#101013 — Re: subprocess check_output

FromCameron Simpson <cs@zip.com.au>
Date2015-12-31 08:02 +1100
SubjectRe: subprocess check_output
Message-ID<mailman.86.1451509358.11925.python-list@python.org>
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>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web