views:

210

answers:

4

I am writing a program in C++ that launches commands from the DOS operating system using the system() command. So far so good I think. But how can I turn off the screen updating in the console window that pops up so I can't see the thousands of messages that are resulting.

Or, alternatively, how can I dump those messages in some other place....ie is there a more elegant way to deal with this rather than just turning off the screen? thanks.

+1  A: 
  1. To prevent the statements themselves from being echoed, put this at the top of the script:

    @echo off

  2. To prevent output from commands, use redirection operators. To discard both the standard output and standard error streams:

    nameofcommand.exe params > nul 2>&1

Note that it is always a good idea to include error handling (checking error levels, etc.) in your scripts, especially if you discard all output as shown above.

binarycoder
He's writing C++, not a batch file.
SLaks
<He's writing C++> Whoops, left out the part about using a batch file to call the program...
binarycoder
+1  A: 

You should use the _popen function, which will write the output to a stream instead of the console.

SLaks
+1  A: 

In the batch file you can redirect the output to a file. E.g. echo this goes to a file > log.txt would write the contents of the echo statement to the file.

See this article on command redirectors.

jeffamaphone
A: 

It's quick and dirty I know, but...alternatively, set the foreground colour of the window to the same colour as of the background in order to hide the texts flashing by, see here for an example of how to do this, its in the 7th posting on that page that shows the code to do so. The color you would want is 0x0, black on black...in that way, it looks blank, and no one would see it..

Dirty I know...admittedly SLaks answer above would be more elegant...

Hope this helps, Best regards, Tom.

tommieb75