在Visual Studio中调试时如何管道输出?

时间:2022-06-12 02:57:57

For example, if I wanted to do it from the command line I would use "a.exe > out.txt". Is it possible to do something similar in Visual Studio when I debug (F5)?

例如,如果我想从命令行执行此操作,我将使用“a.exe> out.txt”。我调试时可以在Visual Studio中执行类似的操作(F5)吗?

3 个解决方案

#1


3  

In project properties:

在项目属性中:

  • enter command line arguments "> out.txt"
  • 输入命令行参数“> out.txt”

  • Disable the hosting process
  • 禁用托管过程

#2


1  

Just checking, you are not looking for outputting within Visual Studio using stuff like

只是检查一下,你不是要在Visual Studio中使用类似的东西来输出

System.Diagnostics.Debug.WriteLine("this goes into the Output window");

System.Diagnostics.Debug.WriteLine(“这进入输出窗口”);

right?

#3


1  

You can redirect using the "command argument" in the project properties.

您可以使用项目属性中的“命令参数”重定向。

You can redirect stdout/err/in from your program as well. find a sample in c++ hereafter the only advantage over the first simpler solution is to be portable.

您也可以从程序中重定向stdout / err / in。以后在c ++中找到一个样本,与第一个更简单的解决方案相比,唯一的优势就是可移植。

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main ()
{
#ifdef _DEBUG
    ofstream mout("stdout.txt");
    cout.rdbuf(mout.rdbuf());
#endif
    cout<< "hello" ;
    return 0;
}

#1


3  

In project properties:

在项目属性中:

  • enter command line arguments "> out.txt"
  • 输入命令行参数“> out.txt”

  • Disable the hosting process
  • 禁用托管过程

#2


1  

Just checking, you are not looking for outputting within Visual Studio using stuff like

只是检查一下,你不是要在Visual Studio中使用类似的东西来输出

System.Diagnostics.Debug.WriteLine("this goes into the Output window");

System.Diagnostics.Debug.WriteLine(“这进入输出窗口”);

right?

#3


1  

You can redirect using the "command argument" in the project properties.

您可以使用项目属性中的“命令参数”重定向。

You can redirect stdout/err/in from your program as well. find a sample in c++ hereafter the only advantage over the first simpler solution is to be portable.

您也可以从程序中重定向stdout / err / in。以后在c ++中找到一个样本,与第一个更简单的解决方案相比,唯一的优势就是可移植。

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main ()
{
#ifdef _DEBUG
    ofstream mout("stdout.txt");
    cout.rdbuf(mout.rdbuf());
#endif
    cout<< "hello" ;
    return 0;
}