Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
Wish I knew the answer to this +1 for a good question. –  Kyle Jan 14 '11 at 18:40
    
@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 '13 at 7:49

8 Answers 8

up vote 13 down vote accepted

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.

share|improve this answer
    
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 '11 at 22:04
    
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. –  Florian Peschka Nov 15 '13 at 10:23

Give this a try:

START /B batchfile
share|improve this answer
1  
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 '11 at 0:04

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 VBS 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!

share|improve this answer

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:
 ...
share|improve this answer

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.

share|improve this answer

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

share|improve this answer

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.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.