473,748 Members | 8,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1979
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**********@o nline.de>, Erik Geiger <Er*********@gm x.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_NOWA IT) can be used directly, as
can os.system("comm and&") (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_NOWA IT) can be used directly, as
can os.system("comm and&") (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**********@o nline.de>, Erik Geiger <Er*********@gm x.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.washingt on.edu
Jul 18 '05 #8
Donn Cave schrieb:
In article <cq**********@o nline.de>, Erik Geiger <Er*********@gm x.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.washingt on.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*********@gm x.de> wrote:
Donn Cave schrieb:
In article <cq**********@o nline.de>, Erik Geiger <Er*********@gm x.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.washingt on.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.co m>
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
5840
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 Mandrake 9.2 and am reinstalling everything. This thing is kicking my ass and I can't seem to get past it. I could really use some help if anybody has any. Just for reference, this was my primary source for information on installation and...
0
4294
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 Mandrake 9.2 and am reinstalling everything. This thing is kicking my ass and I can't seem to get past it. I could really use some help if anybody has any. Just for reference, this was my primary source for information on installation and...
1
2044
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 for a user to be able to use a page on our intranet to start running a time-consuming reporting and analysis job. I'm not sure how to start a process in ASP.NET and then "detach" it, or how to check that it's still running later. I think that maybe...
6
6845
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 process. That's strange for me. I understand that it should be a new shell, but why I can't start it? Is it need to have a Windows application to start an external process? I created a very long batch files and a complicated script to work with...
1
300
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 for a user to be able to use a page on our intranet to start running a time-consuming reporting and analysis job. I'm not sure how to start a process in ASP.NET and then "detach" it, or how to check that it's still running later. I think that maybe...
0
8989
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.