While debugging I want to display console output both on console and save a backup in file.
Windows doesn’t have tee, but you can add one. Say the folder is c:\bin\ and it works fine. And I have added it into system’s PATH.
Problem is setting “[ ]| tee[.exe] output.txt” or ” | tee[.exe] output.txt” won’t work — the output.txt is just nowhere to be found. I also tried to add the c:\bin\ path explicitly in VC Directories or environment under debugging and merge environment to be yes.
“> output.txt” works fine.
Anyone has any idea how I can resolve this? Many thanks!
I assume that you’re putting the
| tee.exe output.txtstring in the project property “Debugging | Command Argument”.Unfortunately, that property only supports the redirection operators, not the pipe operator. If you have the
| tee.exe output.txtstring in the preoperty and run a program that dumps the command line arguments, you’ll see that that information is just passed on as the arguments. The “Debugging | Command Argument” doesn’t actually get processed by a full-fledged shell (such ascmd.exe) – it’s just the IDE supporting some simple redirection (actually, it seems to support more than I expected):From http://msdn.microsoft.com/en-us/library/kcw4dzyf.aspx:
You can have a limited version of what you’re looking for by redirecting the program’s output to a file using
>>and using atail-fcommand to display whatever gets added to the file. If you do this you’ll probably want to callsetvbuf( stdout, NULL, _IONBF, 0 )first thing inmain()so that I/O is unbuffered. Otherwisetail -fwon’t see it until the buffer gets flushed, and I imagine that you’d like to see each output operation as it occurs.Another option is to crank the console window’s “Screen Buffer Height” property up to a large number – one of the first things I do when I get a new Windows machine is set that value to 3000 or so – then debug the program normally and copy/paste the contents of the console window before it closes.