KeyBoard interrupt and Redirection operator
gagsl-py2 at yahoo.com.ar
Tue Sep 15 20:51:47 CEST 2009
En Tue, 15 Sep 2009 15:10:48 -0300, aditya shukla
<adityashukla1983 at gmail.com> escribió:
> I have a program which i use like this scraps.py arg1 arg2 > filename. I
> using the redirection operator to direct the output to the filename .The
> scenario here is that I want to print a message as long as the program
> running and as generate an error message and exit as I use a keyboard
> interrupt.I am able to do this by using a try except clause but the
> issue is
> that everything is written to the file as i am using the redirection
> operator .Is there a way to write the running program message and the
> terminate program mesage to the console without writing it to the file.
You're redirecting stdout, but stderr still goes to the console.
print >>sys.stderr, "This message appears on the console"
More information about the Python-list