472,377 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,377 software developers and data experts.

execute a shell script from a python script

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
7 2865
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Valentine Kouznetsov | last post by:
Hi, simple question, how to execute command in current shell, not in subshell? Example. I have environment variable A=aaa and need to invoke shell (sh) script which will do something with A. If...
3
by: leroybt.rm | last post by:
Can someone tell me how to run a script from a interactive shell I type the following: >>>python filename >>>python filename.py >>>run filename >>>run filename.py >>>/run filename >>>/run...
5
by: Chandra | last post by:
Hi, Is there a way to execute a python script(file) in ASP.NET application (programmatically)?? Regards, Chandra
9
by: sohan | last post by:
Hi, I want to know how to connect and execute a db2 query from inside a UNIX shell script. Details: We have a unix shell script. We need to execute multiple db2 sql queries from this shell...
4
by: brad | last post by:
When I use idle or a shell to execute a python script, the script executes in the directory it is currently in (in this case, my desktop). However, when using GNOME and right clicking the py script...
3
by: telduivel | last post by:
Can someone please help me with this: I have a python script, that at some point calls a linux bash script (.sh). Starting the shell script is the last thing my python script needs to do, so I...
3
by: Gros Bedo | last post by:
Hello :-) I have a question about Python and Linux shell. I have a python program which is permanently resident in the end-user system. I'm currently producing a RPM package, and it works nicely....
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
4
by: devi thapa | last post by:
Hi, I am executing a python script in a shell script. The python script actually returns a value. So, can I get the return value in a shell script? If yes, then help me out. Regards, Devi
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.