By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,254 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

execute a shell script from a python script

P: n/a
Hi all, I know nothing about Python. What I need to do is to get a
Python script to execute a local shell script. I do not need any
output. What would be th eeasiest way to accomplish this?

Thanks!

Jul 17 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
If your script is foo.sh and takes args:
import subprocess
subprocess.call(["foo.sh","args"],shell=True)
Should work fine. check out
http://www.python.org/dev/doc/maint2...ubprocess.html

Enjoy,
THN

spec wrote:
Hi all, I know nothing about Python. What I need to do is to get a
Python script to execute a local shell script. I do not need any
output. What would be th eeasiest way to accomplish this?

Thanks!
Jul 17 '06 #2

P: n/a
Thanks, actually there are no args, is there something even simpler?

Thanks
Frank
Thomas Nelson wrote:
If your script is foo.sh and takes args:
import subprocess
subprocess.call(["foo.sh","args"],shell=True)
Should work fine. check out
http://www.python.org/dev/doc/maint2...ubprocess.html

Enjoy,
THN

spec wrote:
Hi all, I know nothing about Python. What I need to do is to get a
Python script to execute a local shell script. I do not need any
output. What would be th eeasiest way to accomplish this?

Thanks!
Jul 17 '06 #3

P: n/a
On Mon, 2006-07-17 at 16:59 -0700, spec wrote:
Thanks, actually there are no args, is there something even simpler?

Thanks
Frank
Thomas Nelson wrote:
If your script is foo.sh and takes args:
import subprocess
subprocess.call(["foo.sh","args"],shell=True)
Should work fine. check out
http://www.python.org/dev/doc/maint2...ubprocess.html

Enjoy,
THN

spec wrote:
Hi all, I know nothing about Python. What I need to do is to get a
Python script to execute a local shell script. I do not need any
output. What would be th eeasiest way to accomplish this?
>
Thanks!

--
http://mail.python.org/mailman/listinfo/python-list
Check out os.popen4 or the commands module.


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Jul 18 '06 #4

P: n/a
spec wrote:
Thanks, actually there are no args, is there something even simpler?

Thanks
Frank
you could try os.system()
>From the docs:
system(command)
Execute the command (a string) in a subshell. This is implemented
by calling the Standard C function system(), and has the same
limitations. Changes to posix.environ, sys.stdin, etc. are not
reflected in the environment of the executed command.

On Unix, the return value is the exit status of the process encoded
in the format specified for wait(). Note that POSIX does not specify
the meaning of the return value of the C system() function, so the
return value of the Python function is system-dependent.

On Windows, the return value is that returned by the system shell
after running command, given by the Windows environment variable
COMSPEC: on command.com systems (Windows 95, 98 and ME) this is always
0; on cmd.exe systems (Windows NT, 2000 and XP) this is the exit status
of the command run; on systems using a non-native shell, consult your
shell documentation.

Availability: Macintosh, Unix, Windows.

Jul 18 '06 #5

P: n/a
In article <11**********************@m73g2000cwd.googlegroups .com>,
Simon Forman <ro*********@yahoo.comwrote:
>spec wrote:
>Thanks, actually there are no args, is there something even simpler?

Thanks
Frank

you could try os.system()
>>From the docs:

system(command)
Jul 18 '06 #6

P: n/a
As described in the docs I pointed to before:
subprocess.call("foo.sh",shell=True)
Is the way to do it without args. I think it is simplest to learn the
subprocess module because (quoting from the docs) this module intends
to replace several other, older modules and functions, such as:
os.system
os.spawn*
os.popen*
popen2.*
commands.*
This way you only need to learn one thing. Actually I would like to
see some of these older functions deprecated.

THN

Cameron Laird wrote:
In article <11**********************@m73g2000cwd.googlegroups .com>,
Simon Forman <ro*********@yahoo.comwrote:
spec wrote:
Thanks, actually there are no args, is there something even simpler?

Thanks
Frank
you could try os.system()
>From the docs:
system(command)
.
[more detail]
.
.
I'm concerned the follow-ups in this thread have been too subtle.
Here is what you need to know: use system(). A model such as

import os
os.system("my_script")

fulfills exactly the requirements the original poster described.
Jul 18 '06 #7

P: n/a
In article <11**********************@s13g2000cwa.googlegroups .com>,
Thomas Nelson <th*@mail.utexas.eduwrote:
>As described in the docs I pointed to before:
subprocess.call("foo.sh",shell=True)
Is the way to do it without args. I think it is simplest to learn the
subprocess module because (quoting from the docs) this module intends
to replace several other, older modules and functions, such as:
os.system
os.spawn*
os.popen*
popen2.*
commands.*
This way you only need to learn one thing. Actually I would like to
see some of these older functions deprecated.
Jul 18 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.