2

I want to make a batch file that runs a particular program and then the command window exits itself, I tried this cause i will make a shortcut of that batch file so the batch file is in root directory

@echo off 
"program.exe" "mainframe.pkg"

exit

it works but the black windows doesn't disappear and causes a fuss in the program cause it has perimeters. Any way to remove the black ugly CMD window.

Vega
  • 27,856
  • 27
  • 95
  • 103
Mk782001
  • 21
  • 1
  • 1
  • 2

3 Answers3

6

Use the start command.

@echo off
start "" "program.exe" "mainframe.pkg"

The first quoted string after the start command is a console window title (if you are starting a console program); it can be an empty string as in my example. After that, specify the program name and its parameters.

You do not need the exit command at the end of the script. (In fact, I recommend against it without the /b parameter, because if you run the script from a cmd.exe prompt, your cmd.exe window will close without warning.)

Bill_Stewart
  • 22,916
  • 4
  • 51
  • 62
0

You need to add exit 0 to the end of your program like so:

@echo off 
start "program.exe" "mainframe.pkg"

exit /B 0

This should work, but let me know!

owen sziber
  • 144
  • 9
  • Adding the `exit` command at the end of a batch file script without the `/b` parameter will cause it to behave rudely if you want to run the script from an already-open command window. (It will terminate your open command window.) – Bill_Stewart Oct 10 '17 at 18:35
  • Okay, added the exit /B to the program. I did some research though, and it seems that exit 0 works just fine. – owen sziber Oct 11 '17 at 17:24
  • No, you are missing the point. If I am running `cmd.exe` and I run your script, it will terminate my `cmd.exe` session. That is not polite behavior for a script. – Bill_Stewart Oct 12 '17 at 14:11
  • @Bill_Stewart Maybe I am misunderstanding. I thought what he wanted to do was have a script open the program. Then he wanted to close the script black box. If you only have one script session open, and the program, then the exit command won't matter because he only has one script session open. Then the program will stay open then the script will close. maybe some verification from the author of the question will help. – owen sziber Oct 12 '17 at 16:34
0

@echo off

start /B "" "program.exe" "mainframe.pkg"

exit /B 0

  • 2
    Please avoid code only answers. It's best to provide an explanation of why your answer solves the question and why it may be preferable to the other answers provided. – DaveL17 Apr 15 '21 at 23:07