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

时间:2022-08-29 23:15:47

I tried going to project properties, selected debugging under configuration properties, and set command arguments to "> out.txt" (without quotation marks of course). However, when I run the program (with F5) I still see output on the console, and no out.txt file is created. This is just a simple C++ Hello World program. These steps worked for my friend but not for me (he's using VS2008 also). I've heard of disabling the hosting process but it seems that's just for Visual Studio 2005.

我尝试了项目属性,在配置属性下选择调试,并将命令参数设置为“> out.txt”(当然没有引号)。但是,当我运行程序(使用F5)时,我仍然在控制台上看到输出,并且没有创建out.txt文件。这只是一个简单的C ++ Hello World程序。这些步骤适用于我的朋友但不适用于我(他也使用VS2008)。我听说过禁用托管过程,但似乎只适用于Visual Studio 2005。

It appears that "> out.txt" is being passed in as an argument. argc is 3, argv[1] is ">", and argv[2] is "out.txt". Is this not supposed to happen? What can I do to fix it?

似乎“> out.txt”作为参数传递。 argc为3,argv [1]为“>”,argv [2]为“out.txt”。这不应该发生吗?我该怎么做才能解决它?

3 个解决方案

#1


According to this bug report on the Microsoft Connect website, this issue was fixed in Visual Studio 2008 Service Pack 1. I'm running VS2008 SP1 on my system, and output redirection works OK for me. You can download SP1 here.

根据Microsoft Connect网站上的此错误报告,此问题已在Visual Studio 2008 Service Pack 1中得到修复。我在我的系统上运行VS2008 SP1,输出重定向对我来说正常。你可以在这里下载SP1。

#2


I have the same results as you: The redirection doesn't work in 2008 for me either, but does work in 2005. As @ChrisN mentioned, this is a bug with VS 2008 and it was fixed in VS 2008 SP1.

我有与你相同的结果:重定向在2008年对我来说也不起作用,但在2005年有效。正如@ChrisN提到的,这是VS 2008的一个错误,它在VS 2008 SP1中得到修复。

To fix, you can install VS2008 SP1 or use this work around.

要修复,您可以安装VS2008 SP1或使用此工作。

Here is the work around:

这是工作:

  • Redirect the output in code via freopen, this link explains how
  • 通过freopen重定向代码中的输出,此链接解释了如何

  • Wrap this code in #ifdef REDIRECT_OUTPUT_TO_FILE and #endif
  • 将此代码包装在#ifdef REDIRECT_OUTPUT_TO_FILE和#endif中

  • Go to the C/C++ tab, then preprocessor tab, and set REDIRECT_OUTPUT_TO_FILE
  • 转到C / C ++选项卡,然后转到预处理器选项卡,并设置REDIRECT_OUTPUT_TO_FILE

#3


Works perfectly for me in vs 2005. Maybe check the arguments in main() to see if "> out.txt" is passed in as argument instead of being evaluated at the level of cmd.exe

在vs 2005中对我来说非常适合。也许检查main()中的参数,看看是否将“> out.txt”作为参数传入,而不是在cmd.exe级别进行评估

#1


According to this bug report on the Microsoft Connect website, this issue was fixed in Visual Studio 2008 Service Pack 1. I'm running VS2008 SP1 on my system, and output redirection works OK for me. You can download SP1 here.

根据Microsoft Connect网站上的此错误报告,此问题已在Visual Studio 2008 Service Pack 1中得到修复。我在我的系统上运行VS2008 SP1,输出重定向对我来说正常。你可以在这里下载SP1。

#2


I have the same results as you: The redirection doesn't work in 2008 for me either, but does work in 2005. As @ChrisN mentioned, this is a bug with VS 2008 and it was fixed in VS 2008 SP1.

我有与你相同的结果:重定向在2008年对我来说也不起作用,但在2005年有效。正如@ChrisN提到的,这是VS 2008的一个错误,它在VS 2008 SP1中得到修复。

To fix, you can install VS2008 SP1 or use this work around.

要修复,您可以安装VS2008 SP1或使用此工作。

Here is the work around:

这是工作:

  • Redirect the output in code via freopen, this link explains how
  • 通过freopen重定向代码中的输出,此链接解释了如何

  • Wrap this code in #ifdef REDIRECT_OUTPUT_TO_FILE and #endif
  • 将此代码包装在#ifdef REDIRECT_OUTPUT_TO_FILE和#endif中

  • Go to the C/C++ tab, then preprocessor tab, and set REDIRECT_OUTPUT_TO_FILE
  • 转到C / C ++选项卡,然后转到预处理器选项卡,并设置REDIRECT_OUTPUT_TO_FILE

#3


Works perfectly for me in vs 2005. Maybe check the arguments in main() to see if "> out.txt" is passed in as argument instead of being evaluated at the level of cmd.exe

在vs 2005中对我来说非常适合。也许检查main()中的参数,看看是否将“> out.txt”作为参数传入,而不是在cmd.exe级别进行评估