14

I have to run a batch file without showing the command line but the Command line keeps on popping up. This is my code:

@echo off
:SAMPLE
cd /d C:
md %RANDOM%
cd /d D:
md %RANDOM%
cd /d E:
md %RANDOM%
goto SAMPLE
MissJ
  • 147
  • 1
  • 2
  • 8
  • 1
    What do you mean with command line? A prompt? Unlikely, I guess. The executed statements? Possible, if you have something preceding the `@echo off` so that it doesn't work. The console window? Definitely, but you can't solve that with a batch file alone, then. – Joey May 09 '14 at 07:18
  • that's the whole code of my batch file. and i mean, the command prompt window. – MissJ May 09 '14 at 07:34
  • 1
    Possible duplicate of [Running a CMD or BAT in silent mode](http://stackoverflow.com/questions/411247/running-a-cmd-or-bat-in-silent-mode) – user Oct 07 '16 at 01:28

3 Answers3

24

Solution-1:

Save your code in a batch file lets say My.bat

Create a VBScript file lets say Master.vbs and call your My.bat file within it.

Lets assume your batch file is at C:\Test\My.bat then:

Master.vbs:

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Test\My.bat" & Chr(34), 0
Set WshShell = Nothing

It'll run your batch file in invisible/hidden mode.

Solution-2:

If at all possible, modify the batch file to run whatever program with the start command. By default, start returns immediately without waiting for the program to exit, so the batch file will continue to run and, presumably, exit immediately. Couple that with modifying your shortcut to run the batch file minimized, and you’ll only see the taskbar flash without even seeing a window onscreen.

Sunny
  • 7,812
  • 10
  • 34
  • 48
3

The following sample code works

start cmd /c "some command && exit 0"

The trick is => && exit 0

sanbrother
  • 244
  • 3
  • 5
  • This is almost what I'm looking for. For me it still launches the command window, but at least that window doesn't show terminal output and I can close it without stopping the process started by `some command`. It looks like taking the extra step of starting the command like `start /min cmd ...` has the added benefit of minimizing the command line window to begin with, but still doesn't get rid of it. – thehale Apr 10 '21 at 04:40
0

you can use the redirect in the following way:

@echo off
:SAMPLE
cd /d C:
md %RANDOM% >nul 2>&1
cd /d D:
md %RANDOM% >nul 2>&1
cd /d E:
md %RANDOM% >nul 2>&1
goto SAMPLE

Got this from: Suppress command line output

Community
  • 1
  • 1
Alex
  • 917
  • 5
  • 11
  • what do you mean by "command line"? do you mean the command prompt window? – Alex May 09 '14 at 07:31
  • yeah. the batch file should run without it showing the cmd window. – MissJ May 09 '14 at 07:32
  • you can minimize the command prompt window from whatever you're calling the script from like `start /min mybat.bat`, but as Joey pointed out above, there's no other way to do it internally – Alex May 09 '14 at 07:35
  • you can try to run is as a service: http://stackoverflow.com/questions/20902282/running-a-bat-file-in-background-in-windows – Alex May 09 '14 at 07:45