Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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). 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.

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?


2 Answers

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.

like image 139
ChrisN Avatar answered Jan 27 '26 15:01

ChrisN


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.

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

Here is the work around:

  • Redirect the output in code via freopen, this link explains how
  • Wrap this code in #ifdef REDIRECT_OUTPUT_TO_FILE and #endif
  • Go to the C/C++ tab, then preprocessor tab, and set REDIRECT_OUTPUT_TO_FILE
like image 36
Brian R. Bondy Avatar answered Jan 27 '26 14:01

Brian R. Bondy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!