惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
aimingoo的专栏
aimingoo的专栏
H
Help Net Security
L
LangChain Blog
M
MIT News - Artificial intelligence
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Check Point Blog
P
Proofpoint News Feed
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏
博客园_首页
Blog — PlanetScale
Blog — PlanetScale
U
Unit 42
I
InfoQ
月光博客
月光博客
爱范儿
爱范儿
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
博客园 - Franky
D
Docker
B
Blog

博客园 - 珂儿

谈话技巧 用户中心 - 博客园 用户中心 - 博客园 【转载】 正则表达式 致谢 转载:Prototype.js的中文使用手册 Notes of Store Procedure 猫猫感冒了 从我的衣着改变说起 天无绝人之路 Job hunting准备系列一——关于搜索引擎技术 读书疑问汇总 算法题目汇总 How to influence people and win friends 项目经历总结——IBM实习总结 C++程序设计学习笔记 求职经验汇总 《编程之美》笔记
C# Program Output Redirect
珂儿 · 2009-02-06 · via 博客园 - 珂儿

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!