keer哥的点点滴滴

人生格言 为民族立生命,为万世开太平!——连战

These days I met with a problem. I have to run a program that my collegue developed, however, the program displayed its debug information on the console screen (standard output). and I want to store these debug information to some file since I need to use the these information to do some research work. We suppose the .exe file name is "a" here, so I opend cmd.exe, input "a.exe > output.txt" (output.txt is the file I want to use to store debug information), however, the program crashed and threw an exception saying the following words:

The handle is invalid.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.Console.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
   at System.Console.GetBufferInfo()
   at System.Console.Clear()
   at Caller.Invoke()

we can see from the bold red words, in the program, it invoked a method called Console.clear() when it displayed debug info on console screen. However, while we redirected the output to a file, the program could not invoke Console.clear() method correctly then. Although it could redirect all the Console.writeline() or Console.write() to File Output, it could not redirect Console clear to File clear!

However, I still do not know why it could not finish this, if some one knows, please tell me why and thank you so much!

posted on 2009-02-06 11:25  珂儿  阅读(568)  评论(0编辑  收藏  举报