changing current dir and executing a shell script
suresh
suresh.amritapuri at gmail.com
Fri May 27 21:33:18 EDT 2011
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
More information about the Python-list
mailing list