473,327 Members | 1,896 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,327 software developers and data experts.

starting and stopping a program from inside a python script

Aloha!
I want to terminate a process/program from within a python script.

For example,
if I have a program say foo.sh that starts running, then I can run it
from within a python script using
os.popen('foo.sh') which starts a program/process say 'bar'

At some point later, I want to kill 'bar'. Currently, I start off the
process and then when the python script exits, the process 'bar' is
still running and I have to issue ps -ef | grep 'bar' and then kill
it.

Is there any better way of doing this?

Jul 3 '06 #1
1 1662
You can store the pid of the process when started and later use it to kill it.

cheers,

On 3 Jul 2006 15:28:19 -0700, dfaber <de*******@gmail.comwrote:
Aloha!
I want to terminate a process/program from within a python script.

For example,
if I have a program say foo.sh that starts running, then I can run it
from within a python script using
os.popen('foo.sh') which starts a program/process say 'bar'

At some point later, I want to kill 'bar'. Currently, I start off the
process and then when the python script exits, the process 'bar' is
still running and I have to issue ps -ef | grep 'bar' and then kill
it.

Is there any better way of doing this?

--
http://mail.python.org/mailman/listinfo/python-list

--
----
Amit Khemka -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.
Jul 4 '06 #2

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

Similar topics

0
by: Paul Hampton | last post by:
Hi all I'm new to python so please be gentle :) I'm trying to write a module for my media playing PC which will record input directly from the soundcard using LAME. At the moment I can get it...
6
by: David Klaffenbach | last post by:
Is there a way from within a python script to cause the interpreter to be in interactive mode after the script finishes? so that if I run: myscript.py it will always execute as if I had...
9
by: Peter Wu | last post by:
I'm giving vim a try to program Python. The following are the steps I follow to code/test a python program. vi test.py :wq :!python test.py Is there any other way? I don't want to type...
0
by: Nick Coghlan | last post by:
Anyone playing with the CPython interpreter's new command line switch might have noticed that it only works with top-level modules (i.e. scripts that are directly on sys.path). If the script is...
15
by: Nick Coghlan | last post by:
Python 2.4's -m command line switch only works for modules directly on sys.path. Trying to use it with modules inside packages will fail with a "Module not found" error. This PEP aims to fix that...
6
by: tatamata | last post by:
Hello. How can I run some Python script within C# program? Thanks, Zlatko
6
by: Andrew Poulos | last post by:
I'm using Windows Media Audio, via a WAX file, and I have some custom controls to start and stop the audio. While it works in IE, FF gives an error. The HTML looks like this: <object id='obj'...
3
by: Cenarius | last post by:
Hi, I need some help, i don't know much about programming other than executing them get getting them from scripting sites. My program is it won't start a service if the startup type is Disabled. it...
4
by: durumdara | last post by:
Hi! My problem is that: The "test.py" is working in every machine that I use except in my home machine. Formerly it worked but now not. I don't know what happened, I searching for some...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.