简体   繁体   English

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

[英]How do I pipe output when debugging in Visual Studio 2008?

I tried going to project properties, selected debugging under configuration properties, and set command arguments to "> out.txt" (without quotation marks of course). 我尝试了项目属性,在配置属性下选择调试,并将命令参数设置为“> out.txt”(当然没有引号)。 However, when I run the program (with F5) I still see output on the console, and no out.txt file is created. 但是,当我运行程序(使用F5)时,我仍然在控制台上看到输出,并且没有创建out.txt文件。 This is just a simple C++ Hello World program. 这只是一个简单的C ++ Hello World程序。 These steps worked for my friend but not for me (he's using VS2008 also). 这些步骤适用于我的朋友但不适合我(他也使用VS2008)。 I've heard of disabling the hosting process but it seems that's just for Visual Studio 2005. 我听说过禁用托管过程,但似乎只适用于Visual Studio 2005。

It appears that "> out.txt" is being passed in as an argument. 似乎“> out.txt”作为参数传递。 argc is 3, argv[1] is ">", and argv[2] is "out.txt". argc为3,argv [1]为“>”,argv [2]为“out.txt”。 Is this not supposed to happen? 这不应该发生吗? What can I do to fix it? 我该怎么办才能修复它?

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

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

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

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

相关问题 当我安装了多个Visual Studio版本时,如何使用Visual Studio 2008构建增强功能? - How do I build boost with Visual Studio 2008 when I have multiple Visual Studio versions installed? 当我尝试打开资源视图时,Visual Studio 2008崩溃。 我如何解决它? - Visual Studio 2008 crashes when I try to open Resource View. How do i fix it? 视觉工作室2008的输出 - Output in visual studio 2008 如何在调试时将Visual Studio配置为“跳过”智能指针代码? - How do I configure Visual Studio to 'skip' smart pointer code when debugging? Visual Studio 2008调试; 写入值时中断 - Visual studio 2008 debugging; breaking when values are being writen 如何在Visual Studio 2008中折叠选定的代码块? - How do I collapse selected chunks of code in Visual Studio 2008? 如何在Visual Studio 2008中启动新的CUDA项目? - How do I start a new CUDA project in Visual Studio 2008? 如何在visual studio 2008中为我的应用程序设置图标? - How do I set the icon for my application in visual studio 2008? 如何确保在修改.h文件时,使用Visual Studio 2008在Release版本中自动编译包括它的.cc文件? - How do I make sure that when a .h file is modified, the .cc files including it are compiled automatically in a Release build using Visual Studio 2008? Wierdness调试Visual Studio C ++ 2008 - Wierdness debugging Visual Studio C++ 2008
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM