Re: KeyBoard interrupt and Redirection operator
aditya shukla wrote: Hello Guys, I have a program which i use like this scraps.py arg1 arg2 > filename. I am 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 is 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. Thanks Aditya That's what sys.stderr is for. It's redirected independently of stdout, and most people will leave it pointing to the console. You could for example use print >> sys.stderr , "Starting program" DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: KeyBoard interrupt and Redirection operator
aditya shukla wrote: Hello Guys, I have a program which i use like this scraps.py arg1 arg2 > filename. I am 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 is 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. Thanks Aditya There are two output streams usually available to such a program. stdout: Where print's output goes, and is affected by the redirect operator. stderr: Output to this stream is not (normally) affected by the redirect operator. So print stuff or print>>sys.stdout, stuff will go to the redirected file and print>>sys.stderr, stuff will not be redirected. That answers you specific question, but note that various shells *do* provide (other) ways to redirect both stdout and stderr, but for a discussion on that, you will have to tell us what shell, and indeed what OS you are using. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
Re: KeyBoard interrupt and Redirection operator
En Tue, 15 Sep 2009 15:10:48 -0300, aditya shukla escribió: I have a program which i use like this scraps.py arg1 arg2 > filename. I am 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 is 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" -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
KeyBoard interrupt and Redirection operator
Hello Guys, I have a program which i use like this scraps.py arg1 arg2 > filename. I am 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 is 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. Thanks Aditya -- http://mail.python.org/mailman/listinfo/python-list