tags:

views:

13171

answers:

3

How can I run a CMD or .bat file in silent mode? I'm looking to prevent the CMD interface from being shown to the user.

+1  A: 

Include the phrase

@echo off

right at the top of your bat script.

Frederick
Thanks for the edit moocha.
Frederick
Improved it a bit (formatting, added the @ in front so that the echo statement itself doesn't cause output.) However, that will not prevent output from called commands. Redirecting the output to >NUL 2>NUL on calling will do that.
Mihai Limbășan
Heh, welcome. Crossed comments :)
Mihai Limbășan
+6  A: 

I have proposed in StackOverflow question a way to run a batch file in the background (no DOS windows displayed)

That should answer your question.

Here it is:


From your first script, call your second script with the following line:

wscript.exe invis.vbs run.bat %*

Actually, you are calling a vbs script with:

  • the [path]\name of your script
  • all the other arguments needed by your script (%*)

Then, invis.vbs will call your script with the Windows Script Host Run() method, which takes:

  • intWindowStyle : 0 means "invisible windows"
  • bWaitOnReturn : false means your first script does not need to wait for your second script to finish

See the question for the full invis.vbs script:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run """" & WScript.Arguments(0) & """" & sargs, 0, False
                                                            ^^^^^
                                  means "invisible window" ---|


Update after Tammen's feedback:

If you are in a DOS session and you want to launch another script "in the background", a simple /b (as detailed in the same aforementioned question) can be enough:

You can use start /b second.bat to launch a second batch file asynchronously from your first that shares your first one's window.

VonC
A: 

The solution was including the /b option after the start option, script file works flawlessly :-) kudos to VonC for assistance.

Tammen Bruccoleri