Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Java .jar and Windows .exe from bat file

Situation is, i have 3 separate batch files in different locations running start commands on .jar .exe and call command to open index.html through Firefox.

I want to create one global batch-file to run all of these one at a time. Extra hint would be to make a pause (several seconds) in between calling each one of those commands.

These are the commands i am executing in batch files:

echo majmun1
call C:\OKOLINA\additionConsoleApplication1.exe
echo majmun2
call C:\OKOLINA\addition1\jWebSocketSamples-2.0.jar
echo majmun3
call firefox.exe C:\OKOLINA\addition2\index.html
echo majmun4
exit

It only executes call the first one and stops.

like image 443
Tim Avatar asked Mar 26 '26 23:03

Tim


2 Answers

You need to use start istead:

echo majmun1
start C:\OKOLINA\additionConsoleApplication1.exe
echo majmun2
start C:\OKOLINA\addition1\jWebSocketSamples-2.0.jar
echo majmun3
start firefox.exe C:\OKOLINA\addition2\index.html
echo majmun4
exit

If you want to make a pause between starts, then you can use this little hack:

command 1
ping -w 1000 -n 5 127.0.0.1
command 2

It pings localhost 5 times (-n 5) and waits 1000ms (-w 1000) between each ping, effectively delaying execution of command 2 for 5 seconds. (You can't use pause as it waits for a user to press Enter and there is no built-in delay command).

like image 191
Igor Korkhov Avatar answered Mar 28 '26 11:03

Igor Korkhov


Use start instead of call to launch your applications.

call calls one batch program from another (The filename parameter must have a .bat or .cmd extension).

On the other hand, start starts a separate command prompt window to run a specified program or command.