sending ctrl C to a process

S

s99999999s2003

hi
i have a program that works very similar to tail -f in Unix
It will need a Ctrl-C in order to break out of the program.
I wish to run this program using python (either thru os.system() or
some other subprocess modules) and how can i pass Ctrl-C to this
program to terminate it in python?
thanks
 
F

Felipe Almeida Lessa

Em Ter, 2006-03-28 às 18:14 -0800, (e-mail address removed) escreveu:
It will need a Ctrl-C in order to break out of the program.
I wish to run this program using python (either thru os.system() or
some other subprocess modules) and how can i pass Ctrl-C to this
program to terminate it in python?

$ python2.4 && echo " **** Python terminates!"
Python 2.4.2 (#2, Mar 27 2006, 21:07:39)
[GCC 4.0.3 (Debian 4.0.3-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information..... while 1:
.... pass
.... except KeyboardInterrupt:
.... print "\nHey, why did you press Ctrl-C?!"
.... except:
.... print "\nStrange..."
....
^C
Hey, why did you press Ctrl-C?!.... while 1:
.... pass
.... except KeyboardInterrupt:
.... sys.exit(0)
....
^C
**** Python terminates!
$

HTH,
 
S

s99999999s2003

hi
thanks for the reply.Actually, i should clarify what i am doing.
the program's output will be displayed to a web browser using cgi, so
there is no
keyboard interrupt. The backend cgi script (python script) will have to
send Ctrl-C to break the program.
thanks
 
G

Grant Edwards

hi
thanks for the reply.

Please properly quote the article to which you're replying so
that we can tell who/what your talking to/about.
Actually, i should clarify what i am doing. the program's
output will be displayed to a web browser using cgi, so there
is no keyboard interrupt. The backend cgi script (python
script) will have to send Ctrl-C to break the program.

Actually, you don't want to send a Ctrl-C to the program. You
want to send a SIGINT signal to the process. That's what the
tty line-discipline layer in the tty driver sends to processes
attached to a tty when the tty receives the interrupt character
(which defaults to Ctrl-C).

Sending signals to processes is done using os.kill()

http://docs.python.org/lib/os-process.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top