Home > Software design >  How to automatically let cmd close Batch File
How to automatically let cmd close Batch File

Time:11-23

So i have a Javafx Maven Projekt which i run with a .bat

@echo off
set JLINK_VM_OPTIONS=
set DIR=%~dp0
"%DIR%\java" %JLINK_VM_OPTIONS% -m Main/org.openjfx.Main %*

it works but the cmd stays opend and when i close it the project closes aswell i asked the question here but i didnt got a working answer so i just ask here

btw sorry for my bad english

CodePudding user response:

You seem to be uncertain what you need to be kept open, (the sole aim of that batch file is to keep a console window open for visual console feedback) but to answer your request, you need to run your bat file from a cmd prompt, in order to pass parameters otherwise it is mainly redundant.

@echo off
set JLINK_VM_OPTIONS=
set "DIR=%~dp0"
start "" "%DIR%\javaw" %JLINK_VM_OPTIONS% -m Main/org.openjfx.Main %*
rem See notes
rem exit

Note

javaW willstart java for windows in non console mode, thus dismissing the batch file. However if you are running from a cmd console that is a separate exit that's needed as an extra last line, so try with rem first then remove that last rem to see any difference.

If you find javaW is not suitable then remove the W at the end.

CodePudding user response:

What i understand from you is like this question How to automatically close batch program, but keep java program running? try this if it works.

  • Related