将控制台窗口打印到文件中。 [英] Print console windows into a file.

查看:148
本文介绍了将控制台窗口打印到文件中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何将打印在控制台窗口上的所有内容打印成文件?

Hi,

How can i print everything which is printed on the console window into a file?

推荐答案

只需重定向标准输出。例如,如果您的程序名称是 myapp.exe ,则在控制台窗口中键入:

Just redirect the standard output. For instance, if your program's name is myapp.exe then, in the console window, type:
myapp.exe > out.txt



将生成包含应用程序所有标准输出的文本文件out.txt。



您也可以以编程方式重定向标准,请参阅:如何将stdout重定向到来自Visual C / C ++程序的文件在MSDN [ ^ ]。


that would generate the text file out.txt containing all the standard output of your application.

You may also programmatically redirect the standard out, see: "How to redirect stdout to a file from a Visual C/C++ program" at MSDN[^].


作为解决方案1的替代方案:



有时我们需要看到控制台并使文件处于相同的执行状态。重定向控制台输出时,文本不会显示在控制台中。这是解决方案:



抽象出控制台操作,如 Console.Write 控制台.WriteLine :创建自己的方法,或者重现与 Console 相同的界面(它可以帮助您轻松地重构现有的应用程序)。在您自己的方法的实现中,使用现有的控制台方法加上写入文件的方法。根据某些选项,将输出切换到控制台,文件或两者。用户可以在命令行中选择适当的选项(包括文件名)。



-SA
As the alternative to Solution 1:

Sometimes we need to see the console and have the file at the same execution. When a console output is redirected, the text is not show in the console. Here is the solution:

Abstract out console operations like Console.Write and Console.WriteLine: create your own methods, perhaps reproduce the same interface as Console's (it will help you to refactor existing applications easily). In the implementation of your own methods, use existing console method plus methods writing to a file. Depending on some options, switch output to console, file, or both. The user can choose appropriate options (including also the file name) in a command line.

—SA

这篇关于将控制台窗口打印到文件中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆