开发者

turn off screen updating in a dos batch file

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


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜