views:

775

answers:

3

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?

A: 

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

driAn
+1  A: 

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
Brian R. Bondy
+3  A: 

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.

ChrisN