Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6437
| Subject | Re: changing current dir and executing a shell script |
|---|---|
| From | Albert Hopkins <marduk@letterboxes.org> |
| Date | 2011-05-27 18:19 -0400 |
| References | <c49d698b-183f-46a2-8367-c7db0761ba19@glegroupsg2000goo.googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2178.1306534772.9059.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
changing current dir and executing a shell script suresh <suresh.amritapuri@gmail.com> - 2011-05-27 14:25 -0700
Re: changing current dir and executing a shell script Thorsten Kampe <thorsten@thorstenkampe.de> - 2011-05-28 00:18 +0200
Re: changing current dir and executing a shell script Albert Hopkins <marduk@letterboxes.org> - 2011-05-27 18:19 -0400
Re: changing current dir and executing a shell script Peter Otten <__peter__@web.de> - 2011-05-28 09:41 +0200
Re: changing current dir and executing a shell script Albert Hopkins <marduk@letterboxes.org> - 2011-05-28 17:52 -0400
csiph-web