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


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

Re: changing current dir and executing a shell script

Started bysuresh <suresh.amritapuri@gmail.com>
First post2011-05-27 18:33 -0700
Last post2011-05-27 18:33 -0700
Articles 1 — 1 participant

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


Contents

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

#6445 — Re: changing current dir and executing a shell script

Fromsuresh <suresh.amritapuri@gmail.com>
Date2011-05-27 18:33 -0700
SubjectRe: changing current dir and executing a shell script
Message-ID<mailman.2184.1306546407.9059.python-list@python.org>
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

[toc] | [standalone]


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


csiph-web