473,508 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sending ctrl C to a process

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

Mar 29 '06 #1
3 11364
Em Ter, 2006-03-28 Ã*s 18:14 -0800, s9************@yahoo.com 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.
^C KeyboardInterrupt try: .... while 1:
.... pass
.... except KeyboardInterrupt:
.... print "\nHey, why did you press Ctrl-C?!"
.... except:
.... print "\nStrange..."
....
^C
Hey, why did you press Ctrl-C?! import sys
try:

.... while 1:
.... pass
.... except KeyboardInterrupt:
.... sys.exit(0)
....
^C
**** Python terminates!
$

HTH,

--
Felipe.

Mar 29 '06 #2
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

Mar 29 '06 #3
On 2006-03-29, s9************@yahoo.com <s9************@yahoo.com> wrote:
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

--
Grant Edwards grante Yow! How do I get HOME?
at
visi.com
Mar 29 '06 #4

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

Similar topics

4
7853
by: Per Magnus L?vold | last post by:
Hi, I am working with a simple Java program which communicates over the serial port with a GSM modem. Using Hypertermial, I can send messages and need to press control-z to process the messages....
1
9197
by: Marc | last post by:
Hi all, In searching for an answer to this problem I found several solutions dealing with Unix but none dealing with Windows. Basically I want to send a ping for an indefinite period of time,...
4
13942
by: Scott | last post by:
I am using a TCPIP connection to communicate over port 23 (telnet) to a server, and I am having to mimic normal command line interface you owuld see in a telnet session (i.e. I have to write to...
4
7076
by: Jarod_24 | last post by:
I got a "Process A" that starts several other programs. Sometimes i want to send KeyBoard commands to these programs when i start them. For Example: 1. Process A starts Outlook Process now...
2
8619
by: s99999999s2003 | last post by:
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...
4
6390
by: cartoper | last post by:
I am in a pickel, I MUST start and stop the apache web server in console mode. The only way to shut down apache cleaning is by pressing <Ctrl>+C. I have tried everything I know and I cannot...
3
9632
by: Daniel Clark | last post by:
I have a Windows command line based application that only shuts down cleanly if it sees "CTRL-C" on the console. I need to automate the running of this application, but still allow the user sitting...
1
1452
rhitam30111985
by: rhitam30111985 | last post by:
Hi all .. i am trying to do something really weird ... here is my code : import os os.system("mail -s test xxx@gmail.com asdaskdjkasdaasdad")
7
14149
by: gamename | last post by:
Hi, I really like this recipe for controlling subprocesses: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440554 However, I can't figure out how I can send the equivalent of...
0
7342
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,...
0
7410
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7067
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
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...
1
5060
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...
0
4729
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...
0
3215
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...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
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 ...

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.