visual studio 将debug结果重定向到文件输出

1 重定向

对重定向了解的可直接看2.

1.1 如何重定向(输出)

输出重定向主要通过>>>实现,

command > file 将输出重定向到 file,file不存在则创建,存在则替换
command >> file 将输出以追加的方式重定向到 file,file不存在则创建,存在在追加

1.2 确定重定向文件

以下两组重定向命令实际上等效,其中1表示标准输出文件(stdout),即程序中使用printf或fprintf(stdout,打印的输出

command > file
command >> file
command 1> file
command 1>> file

若想重定向标准错误文件(stderr)的应该使用,即程序中使用fprintf(stder'r,打印的输出

command 2> file
command 2>> file

如果希望将 stdout 和 stderr 合并后重定向到 file,则可以这样写,

command > file 2>&1
command >> file 2>&1

2 Visual Studio debug时的重定向

若通过命令行来运行生成的程序,可以通过1中的方法正常进行重定向操作。Debug时也类似,可以在以下位置通过设置命令行参数的方法实现。
Configuration Properties > Debugging > Command Argments
设置后程序输出将被重定向到$(ProjectDir)\out2.txt
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/iceboy314159/article/details/105877073