Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Cameron Simpson Newsgroups: comp.lang.python Subject: Re: subprocess check_output Date: Thu, 31 Dec 2015 08:02:27 +1100 Lines: 34 Message-ID: References: Reply-To: python-list@python.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed X-Trace: news.uni-berlin.de zNrD1hjXks1Uu9vHpAy5BQRXRUblJ4sdCInPq5JZdAbQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'failing': 0.05; 'bash': 0.07; 'cc:addr:python-list': 0.09; 'scripts': 0.09; 'portable': 0.09; '...)': 0.16; '/bin/sh': 0.16; 'bash,': 0.16; 'bourne': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'reason.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'shell:': 0.16; 'simpson': 0.16; 'transcript': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'parameter': 0.22; 'cc:no real name:2**0': 0.22; 'thanks,': 0.24; 'tried': 0.24; 'plain': 0.24; 'unix': 0.24; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'command': 0.26; 'installed': 0.26; '(which': 0.26; 'linux': 0.26; 'skip:" 20': 0.26; 'finally,': 0.27; 'does,': 0.29; 'code': 0.30; 'skip:s 30': 0.31; 'getting': 0.33; 'run': 0.33; 'common': 0.33; 'file': 0.34; 'worked': 0.34; 'running': 0.34; 'exist': 0.35; 'path': 0.35; 'skip:> 10': 0.35; 'but': 0.36; 'should': 0.36; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'received:localdomain': 0.38; 'drop': 0.38; 'does': 0.39; 'your': 0.60; 'provide': 0.61; 'confirm': 0.62; 'providing': 0.62; 'benefit': 0.66; 'cameron': 0.66; 'header:Reply-To:1': 0.67; 'reply': 0.68; 'subject': 0.70; 'reply-to:no real name:2**0': 0.71; 'special': 0.73; 'fetish': 0.84; 'reply-to:addr:python.org': 0.84; 'carlos': 0.91 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101013 On 30Dec2015 21:14, Carlos Barera 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