简体   繁体   English

使用输出重定向打印到命令行

[英]Printing to command-line with output redirection

I use printf() in my C++ application to print some information when I run it from Linux command-line. 从Linux命令行运行时,我在C ++应用程序中使用printf()打印一些信息。 Now, I am using output redirection (./main > output.txt) to save the results into file. 现在,我正在使用输出重定向(./main> output.txt)将结果保存到文件中。 I was wondering if it is possible to have both at the same time: see the result in command-line while the program is running, and do output redirection; 我想知道是否可以同时使用两者:在程序运行时在命令行中查看结果,并进行输出重定向; without explicitly doing it by file I/O in C++. 无需在C ++中通过文件I / O明确地执行此操作。

Do you need a solution in the program? 您是否需要该程序中的解决方案? Because if not, you can pipe the output into tee which takes its input and pumps in into both a file and stdout. 因为如果没有,您可以将输出通过管道teetee ,后者将接受输入并将其泵入文件和stdout。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM