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


Groups > comp.lang.python > #6445

Re: changing current dir and executing a shell script

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <suresh.amritapuri@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'python.': 0.04; 'subject:changing': 0.07; 'filename': 0.09; 'subject:current': 0.09; 'subprocess': 0.09; '>>>': 0.12; 'wrote:': 0.14; 'default).': 0.16; 'message- id:@glegroupsg2000goo.googlegroups.com': 0.16; 'reply- to:addr:comp.lang.python': 0.16; 'to:addr:comp.lang.python': 0.16; 'argument': 0.16; 'cc:addr:python-list': 0.17; '27,': 0.19; 'keyword': 0.19; 'shell': 0.19; 'command': 0.19; 'header:In-Reply- To:1': 0.21; 'cc:2**0': 0.22; 'stuff': 0.22; 'cc:no real name:2**0': 0.23; 'works.': 0.23; 'fri,': 0.23; 'tried': 0.27; 'import': 0.29; 'cc:addr:python.org': 0.30; 'hi,': 0.31; 'does': 0.33; 'received:209.85.212': 0.34; 'thank': 0.35; 'header:User- Agent:1': 0.35; '-0700,': 0.35; 'version.': 0.35; 'received:google.com': 0.37; 'received:209.85': 0.37; '(by': 0.37; 'friday,': 0.37; 'but': 0.38; 'execute': 0.38; 'subject:: ': 0.38; 'skip:s 20': 0.39; 'received:209': 0.39; 'within': 0.60; 'to:addr:googlegroups.com': 0.63; 'skip:$ 10': 0.66; 'due': 0.67; 'header:Reply-To:1': 0.72; 'reply-to:no real name:2**0': 0.72; 'reply-to:addr:googlegroups.com': 0.73; 'calls,': 0.84; 'albert': 0.91
Newsgroups comp.lang.python
Date Fri, 27 May 2011 18:33:18 -0700 (PDT)
In-Reply-To <mailman.2178.1306534772.9059.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=169.235.17.37; posting-account=Q6FYUQoAAAAK21zFzPM6TEGh78LrUT3V
User-Agent G2/1.0
X-Google-Web-Client true
MIME-Version 1.0
Subject Re: changing current dir and executing a shell script
From suresh <suresh.amritapuri@gmail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To comp.lang.python@googlegroups.com
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.2184.1306546407.9059.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 82.94.164.166
X-Trace 1306546407 news.xs4all.nl 49182 [::ffff:82.94.164.166]:51699
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6445

Show key headers only | View raw


On Friday, May 27, 2011 3:19:22 PM UTC-7, Albert Hopkins wrote:
> On Fri, 2011-05-27 at 14:25 -0700, suresh wrote:
> > Hi,
> > I want to execute the following command line stuff from inside python. 
> > $cd directory
> > $./executable
> > 
> > I tried the following but I get errors
> > import subprocess
> > subprocess.check_call('cd dir_name;./executable')
> > 
> > Due to filename path issues, I cannot try this version.
> > subprocess.check_call('./dir_name/executable')
> > 
> 
> You don't want to do this because "cd" is a built-in shell command, and
> subprocess does not execute within a shell (by default).
> 
> The proper way to do this is to use the "cwd" keyword argument to
> subprocess calls, i.e.:
> 
> >>> subprocess.check_call(('/path/to/exec',), cwd="/path/to/dir")
> 
> -a

It works. thank you very much. I have been struggling with this for a veryyyyy long time. 
suresh

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


Thread

Re: changing current dir and executing a shell script suresh <suresh.amritapuri@gmail.com> - 2011-05-27 18:33 -0700

csiph-web