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

推荐订阅源

WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
Vercel News
Vercel News
Last Week in AI
Last Week in AI
H
Help Net Security
The Cloudflare Blog
L
LangChain Blog
Microsoft Security Blog
Microsoft Security Blog
B
Blog RSS Feed
云风的 BLOG
云风的 BLOG
I
InfoQ
U
Unit 42
美团技术团队
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
A
About on SuperTechFans
宝玉的分享
宝玉的分享
量子位
博客园_首页

博客园 - 珂儿

谈话技巧 用户中心 - 博客园 用户中心 - 博客园 【转载】 正则表达式 致谢 转载: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!