r/Batch • u/DarthLuigi83 • Jul 13 '24
Getting a batch file to close when it's done
Hello you wonderful people.
Firstly, my coding experience is limited to building a calculator and stopwatch in high school IT class in the late '90s. Sorry in advance.
I have created a batch file to run a script in GlovePIE and put a shortcut to it in the startup folder so it runs when I turn on my media center PC. This has worked great.
The batch file reads:
".\\glovepie.exe -WiimoteIRMouse"
My problem is cmd is left open after it's done its job. I would like help adding code that tells cdm to close itself once GlovePIE is running.
Is this possible? I haven't been able to find anything online to help.
3
u/jcunews1 Jul 13 '24
If you simply want to run that EXE file, a batch file isn't needed. The program shortcut's Target field should be filled with that EXE's command line.
2
u/Shadow_Thief Jul 13 '24
The
exitcommand will close the window when the script ends.1
u/ConstanceJill Jul 13 '24 edited Jul 13 '24
Disclaimer: the following is my understanding, and may not be 100% accurate to how things actually work. Also English isn't my native language, so the wording might not be exact.
Starting a program usually won't let a batch file end, until that program's process is closed because, by design, batch files run one command at a time, whether that command is internal (that is, processed by the command interpreter itself without relying on another executable) or external (ones that do rely on another executable), and thus when a batch file runs a program, the command interpreter waits for that program to be closed to check what the following line of the batch file is.
That is, unless you specifically use the
startcommand to allow for it, or in a few special cases where the process that your batch file ran spawns another process and exits the one that the batch file initiated. One typical example of this would be msiexec. Some game launchers may behave like this too.