Run a Program and exit the cmd window
Asked Answered
C

3

5

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.

Cullin answered 4/10, 2017 at 16:50 Comment(1)
Use the START command to run your program.Realm
R
9

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

Runesmith answered 4/10, 2017 at 18:55 Comment(0)
M
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!

Maxwellmaxy answered 4/10, 2017 at 18:52 Comment(4)
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.)Runesmith
Okay, added the exit /B to the program. I did some research though, and it seems that exit 0 works just fine.Maxwellmaxy
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.Runesmith
@Runesmith 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.Maxwellmaxy
H
0

@echo off

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

exit /B 0

Honorarium answered 15/4, 2021 at 19:37 Comment(1)
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.Arvonio

© 2022 - 2024 — McMap. All rights reserved.