473,378 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

how to start a new process while the other ist running on

Hi,

sorry, my english ist not that got but I'll try.

I have a running python script (capisuit incoming.py). This script shall
start a linux shell script. If I start this script like os.system(/paht/to
shellscipt.sh) the python scipt waits for the exit of the shell script and
then goes on with the rest of the python script.

How to start a shell script without waiting for the exit of that shell
script? It shall start the shell script and immediately execute the next
python command.

Thanks for any hints

Erik
--
Jemanden wie ein rohes Ei zu behandeln kann auch bedeuten, ihn in die Pfanne
zu hauen.
Jul 18 '05 #1
9 1959
Quickie:

os.system("/path/to/script.sh &")

More elegant, have a look at threads

------------
Harlin Seritt

Erik Geiger wrote:
Hi,

sorry, my english ist not that got but I'll try.

I have a running python script (capisuit incoming.py). This script shall
start a linux shell script. If I start this script like os.system(/paht/to
shellscipt.sh) the python scipt waits for the exit of the shell script and
then goes on with the rest of the python script.

How to start a shell script without waiting for the exit of that shell
script? It shall start the shell script and immediately execute the next
python command.

Thanks for any hints

Erik

Jul 18 '05 #2


See the os. spawn* functions. For example

os.spawnv(os.P_NOWAIT, /path/to/script, args)

/Jean Brouwers

In article <cq**********@online.de>, Erik Geiger <Er*********@gmx.de>
wrote:
Hi,

sorry, my english ist not that got but I'll try.

I have a running python script (capisuit incoming.py). This script shall
start a linux shell script. If I start this script like os.system(/paht/to
shellscipt.sh) the python scipt waits for the exit of the shell script and
then goes on with the rest of the python script.

How to start a shell script without waiting for the exit of that shell
script? It shall start the shell script and immediately execute the next
python command.

Thanks for any hints

Erik

Jul 18 '05 #3
Erik Geiger wrote:
I have a running python script (capisuit incoming.py). This script shall
start a linux shell script. If I start this script like os.system(/paht/to
shellscipt.sh) the python scipt waits for the exit of the shell script and
then goes on with the rest of the python script.

How to start a shell script without waiting for the exit of that shell
script? It shall start the shell script and immediately execute the next
python command.


if you have Python 2.4, you can use the subprocess module:

http://docs.python.org/lib/module-subprocess.html

see the spawn(P_NOWAIT) example for how to use it in your
case:

http://docs.python.org/lib/node236.html

as others have noted, os.spawn(P_NOWAIT) can be used directly, as
can os.system("command&") (where the trailing "&" tells the shell to run
the command in the background).

subprocess is available for Python 2.2 and 2.3 as well, by the way:

http://www.lysator.liu.se/~astrand/popen5/

</F>

Jul 18 '05 #4
Fredrik Lundh schrieb:
Erik Geiger wrote:
[...]
How to start a shell script without waiting for the exit of that shell
script? It shall start the shell script and immediately execute the next
python command.


if you have Python 2.4, you can use the subprocess module:

http://docs.python.org/lib/module-subprocess.html

see the spawn(P_NOWAIT) example for how to use it in your
case:

http://docs.python.org/lib/node236.html


Thats what I've tried, but it did not work. Maybe it's because I want to
start something like su -c '/path/to/skript $parameter1 $parameter2' user
I don't understand the syntax of spawn os.spawnlp(os.P_NOWAIT, "/path/to
script", "the script again?", "the args for the script?")

as others have noted, os.spawn(P_NOWAIT) can be used directly, as
can os.system("command&") (where the trailing "&" tells the shell to run
the command in the background).
Thats what I've used in the Shellscript, but I haven't realized how to use
it in thy python script, thanks! :)

subprocess is available for Python 2.2 and 2.3 as well, by the way:

http://www.lysator.liu.se/~astrand/popen5/

</F>


Erik
--
Jemanden wie ein rohes Ei zu behandeln kann auch bedeuten, ihn in die Pfanne
zu hauen.
Jul 18 '05 #5
Jean Brouwers schrieb:


See the os. spawn* functions. For example

os.spawnv(os.P_NOWAIT, /path/to/script, args)

/Jean Brouwers

Thats what I've tried, but failed.

Thanks anyway ;-)

Greets

Erik
[...]
--
Jemanden wie ein rohes Ei zu behandeln kann auch bedeuten, ihn in die Pfanne
zu hauen.
Jul 18 '05 #6
Thanks, thats what I use now :)

Harlin Seritt schrieb:
Quickie:

os.system("/path/to/script.sh &")

More elegant, have a look at threads

------------
Harlin Seritt

Erik Geiger wrote:
Hi,

sorry, my english ist not that got but I'll try.

I have a running python script (capisuit incoming.py). This script shall
start a linux shell script. If I start this script like
os.system(/paht/to shellscipt.sh) the python scipt waits for the exit of
the shell script and then goes on with the rest of the python script.

How to start a shell script without waiting for the exit of that shell
script? It shall start the shell script and immediately execute the next
python command.

Thanks for any hints

Erik


--
Jemanden wie ein rohes Ei zu behandeln kann auch bedeuten, ihn in die Pfanne
zu hauen.
Jul 18 '05 #7
In article <cq**********@online.de>, Erik Geiger <Er*********@gmx.de>
wrote:
Fredrik Lundh schrieb:
Erik Geiger wrote:

[...]
How to start a shell script without waiting for the exit of that shell
script? It shall start the shell script and immediately execute the next
python command.


if you have Python 2.4, you can use the subprocess module:

http://docs.python.org/lib/module-subprocess.html

see the spawn(P_NOWAIT) example for how to use it in your
case:

http://docs.python.org/lib/node236.html


Thats what I've tried, but it did not work. Maybe it's because I want to
start something like su -c '/path/to/skript $parameter1 $parameter2' user
I don't understand the syntax of spawn os.spawnlp(os.P_NOWAIT, "/path/to
script", "the script again?", "the args for the script?")


Unfortunately this particular case kind of dilutes the advantages
of spawnv. In the common case, parameter1 et al. would be submitted
directly as the parameter list. I believe it may be clearer to start
with to think about the spawnv() function -
os.spawnv(os.P_NOWAIT, path, [cmdname, parameter1, parameter2])

If one of the parameters is itself another command, then of course
it has to be rendered as a string
os.spawnv(os.P_NOWAIT, '/bin/su', ['su', '-c', '%s %s %s' % (cmd,
parameter1, parameter2)])
so you have almost as much work to scan the parameters for shell
metacharacters as you would have with system().

Donn Cave, do**@u.washington.edu
Jul 18 '05 #8
Donn Cave schrieb:
In article <cq**********@online.de>, Erik Geiger <Er*********@gmx.de>
wrote: [...]
Thats what I've tried, but it did not work. Maybe it's because I want to
start something like su -c '/path/to/skript $parameter1 $parameter2'
user

Unfortunately this particular case kind of dilutes the advantages
of spawnv. In the common case, parameter1 et al. would be submitted
directly as the parameter list. I believe it may be clearer to start
with to think about the spawnv() function -
os.spawnv(os.P_NOWAIT, path, [cmdname, parameter1, parameter2])

If one of the parameters is itself another command, then of course
it has to be rendered as a string
os.spawnv(os.P_NOWAIT, '/bin/su', ['su', '-c', '%s %s %s' % (cmd,
parameter1, parameter2)])
so you have almost as much work to scan the parameters for shell
metacharacters as you would have with system().

Donn Cave, do**@u.washington.edu

OK, thats too high for me ;-)

Is the %s the variable for the following commands/parameters? If I have
three parameters, I'll need one more %s? Where to write the user for the su
command?

Well, I've given up ;-)

Thanks for the explanation!

Erik
--
Jemanden wie ein rohes Ei zu behandeln kann auch bedeuten, ihn in die Pfanne
zu hauen.
Jul 18 '05 #9
On 2004-12-22, Erik Geiger <Er*********@gmx.de> wrote:
Donn Cave schrieb:
In article <cq**********@online.de>, Erik Geiger <Er*********@gmx.de>
wrote:

[...]
> Thats what I've tried, but it did not work. Maybe it's because I want to
> start something like su -c '/path/to/skript $parameter1 $parameter2'
> user

Unfortunately this particular case kind of dilutes the advantages
of spawnv. In the common case, parameter1 et al. would be submitted
directly as the parameter list. I believe it may be clearer to start
with to think about the spawnv() function -
os.spawnv(os.P_NOWAIT, path, [cmdname, parameter1, parameter2])

If one of the parameters is itself another command, then of course
it has to be rendered as a string
os.spawnv(os.P_NOWAIT, '/bin/su', ['su', '-c', '%s %s %s' % (cmd,
parameter1, parameter2)])
so you have almost as much work to scan the parameters for shell
metacharacters as you would have with system().

Donn Cave, do**@u.washington.edu

OK, thats too high for me ;-)

Is the %s the variable for the following commands/parameters? If I have
three parameters, I'll need one more %s? Where to write the user for the su
command?

Well, I've given up ;-)


Hey, don't give up. There is help. ;-) guess...

There is a package called pyNMS (http://sourceforge.net/projects/pynms)
That has a module called "proctools", and also one called "sudo". Once
you set up sudo correctly, you can do what you want easily.

However, be aware that proctools spawns a process with the subprocess
stdio connected to _your_ parent process, and does not inherit the stdio
of the parent. So, if the subprocess writes a lot of stuff you must read
it, or the subprocess will block. However, there is some (perhaps buggy)
support for asynchronous operation where those reads happen
automatically (on Linux).


--
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
Keith Dart <kd***@kdart.com>
public key: ID: F3D288E4
================================================== ===================
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark Adams | last post by:
I am a relative newbie to MySQL. I had a Postfix+Courier+MySQL mail server running for several months. It took me a week or so to get it up and running in September. Now, I did a clean upgrade to...
0
by: Mark Adams | last post by:
I am a relative newbie to MySQL. I had a Postfix+Courier+MySQL mail server running for several months. It took me a week or so to get it up and running in September. Now, I did a clean upgrade to...
1
by: Marc | last post by:
I want to write a C#/ASP.NET application where a user can go to a web page, start running a job, close their browser, and then come back later and see the results. The purpose for this application is...
6
by: Dmitri Shvetsov | last post by:
Hi, Can I start an external process from the Web Service? I'm using a code, compiler keeps silence, compiles ok and starts the project. When I trace in Debugger it doesn't start an external...
1
by: Marc | last post by:
I want to write a C#/ASP.NET application where a user can go to a web page, start running a job, close their browser, and then come back later and see the results. The purpose for this application is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.