69

I have installed a ruby gem called Redcar, which is launched from the command line. When it runs, it steals the shell until it terminates, so I have to create a new shell window to continue doing command line work. The shell I'm using is the GITBash shell from MySysGit.

I found a Redcar.bat file which is meant to launch Redcar as a shortcut, I presume, but I don't want the extra command prompt window to open whenever I launch the BAT file.

How do I just run the BAT without seeing the prompt?

5
  • 2
    Wish I knew the answer to this +1 for a good question. Jan 14, 2011 at 18:40
  • If you are still interested in not showing the console window at all, here is a solution from stackoverflow that worked for me(in my case I didn't put anything in the registry, but where I needed).
    – radeklat
    Apr 29, 2012 at 13:45
  • @Kyle a similar question has been asked before superuser.com/questions/191149/how-to-execute-cmd-exe-silently mentions HSTART and briefly mentions that a VBS file can launch it too
    – barlop
    Jan 2, 2013 at 7:49
  • Can you update your selected answer? Is it possible and very simple when you know how.. batch file: line 1: set var1=hello.txt line 2: start "test" notepad.exe "%~dp0%var1%"
    – kodybrown
    Jan 12, 2015 at 6:14
  • Simply use :: or @REM. Source: superuser.com/a/843754/101936 Sep 5, 2015 at 10:51

11 Answers 11

43

You can't -- executing a batch file with the built in Command Prompt is going to keep a window open until the batch file exits.

What you can do is take steps to make sure that the batch file exits as quickly as possible. 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.

One caveat to this is that if you're running a console-mode program, which many script interpreters are, the batch file will wait for the program to exit, and using start will spawn a new console window. What you need to do in this case is run the Windows-based version of the interpreter instead of the console-based one -- no start necessary. For Perl, you would run wperl.exe instead of perl.exe. For Python, it's pythonw.exe instead of python.exe. The old win32 Ruby distribution I have downloaded has rubyw.exe, which should do the same thing.

A final possibility is to use a 3rd-party tool to run the command prompt with a hidden window. I've heard of such things but never had a use for them, so I don't know of anything in particular to point you to.

5
  • Thanks that answers my question. What was really annoying was not that the prompt window appeared but that it had to stay open as long as the program was running. Now the flash is totally bearable, and not nearly as annoying. Will check if I can modify script to run rubyw instead of ruby.
    – Jake
    Jan 21, 2011 at 22:04
  • 1
    So much thanks for explainig the difference between "python" any "pythonw" -- finally I found the solution to running the python window tools we have without the command prompt in the background.
    – F.P
    Nov 15, 2013 at 10:23
  • ´java.exe´ and ´javaw.exe´ are the same.
    – redbeam_
    Apr 25, 2015 at 9:12
  • You can - just not in the batch code itself. really there are a number of Qs on here with As about how to hide the command prompt superuser.com/questions/62525/… superuser.com/questions/191149/how-to-execute-cmd-exe-silently
    – barlop
    Dec 12, 2015 at 20:30
  • 1
    You absolutely can with a simple wscript! You can even create it from within a batch file as .vbs is also encoded in plain text!
    – Mark Deven
    Jan 16, 2020 at 2:17
26

I think this is the easiest and shortest solution to running a batch file without opening the DOS window, it can be very distracting when you want to schedule a set of commands to run periodically, so the DOS window keeps popping up, here is your solution. Use a VB Script to call the batch file ...

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

Copy the lines above to an editor and save the file with .VBS extension. Edit the .BAT file name and path accordingly. Then just run the .vbs file and the magic happens!

You can create a task on Task Scheduler then in the Action should be Start a program then select this .vbs script you created. Depending on your requirements the other properties you can fill and save.

0
11

You can run another batch file with START /MIN CMD.EXE /C mybatchfile.bat from within the command prompt.

From outside it will bring the cmd console window but to avoid that, you can create a shortcut file with properties modified to start minimized.

1
  • 2
    In Windows 8.1, this option is in Properties -> Shortcut tab -> Run: -> Minimized (default is "Normal Window")
    – pix
    Aug 28, 2014 at 19:41
7

Continuing on Dennis Williamson's answer, you can edit the batch file and append (prepend) START /B to the command you are executing.

For example, I have a batch file that runs putty and had the same problem (extra CMD), so this is how I wrote it:

@ECHO OFF
START /B putty.exe -load name_of_my_config_file

It worked perfectly.

7

To do this, use the program Bat To Exe Converter to convert your batch file to an executable file.

When converting into an executable, you will find an option to run your file as an Invisible application in the visibility section. Thus, when you run it, it will run without a window.

Bat to exe

0
6

Give this a try:

START /B batchfile

note added by barlop

start /? says of /B

 B           Start application without creating a new window. The
             application has ^C handling ignored. Unless the application
             enables ^C processing, ^Break is the only way to interrupt
             the application.
1
  • 3
    That might work if I have a command prompt open, but when I am using the .bat I am double clicking it or a shortcut to it on my desktop. I'm trying to avoid having to have a command prompt to launch this program.
    – Jake
    Jan 15, 2011 at 0:04
3

I'm not clear as to your issue, but with some of my batch files, I use a "dumy" who's only purpose is to launch the main batch file.

So GO.BAT will have:

cmd /c go2.bat %1 %2 %3
exit

The exit closes the command prompt window that would otherwise remain open.

And GO2.BAT will have the actually batch file contents that I wish.

  @echo off
  set userid=

  if NOT [%1]==[] goto userid:
  set /p userid=Enter USERID:  
  goto set_usr:

 :userid
 set userid=%1
 shift

 :set_usr
 if %userid%==steven goto steven:
 ...
3

You could use RunHiddenConsole

hideExec.bat

@echo off
RunHiddenConsole batch.bat
1

Just put the /b switch in front of the path. It won't open the second command prompt.

0

Indago's answer has been the best solution for me so far. The VBS file allows me to run the batch's functionality through the script, preventing the CMD window from happening in the first place. There are a few caveat's though:

  1. If your batch requires admin rights, create or use an existing batch that calls the VBS and run that batch as Administrator.

  2. With no visibiity, it can be difficult to discern if what you're trying to do is actually running the way you want it to.

With that said, I'd put a little mock set-up/unit test up first to make sure it's working exactly the way you want it to, before integrating it.

0

I've used cmdow in the past, and it seems to have worked for what I want.

You'll probably want to use one of the following options: CMDOW [window] /HID

/HID hides the specified window

CMDOW [window] /END

/END closes the specified window

CMDOW [window] /CLS

/CLS politely asked the window to close (some windows may open a dialogue box)

Hope this helps.

Not the answer you're looking for? Browse other questions tagged .