0

I've made a batch file which needs to open the browser at localhost and start a java program.

Simplified this currently is :

start "" http://localhost
java -start_java_program

This works fine but the browser is now already started before java is done starting the local server. So you get a not found page.

I can't execute the start command after the java command because the java keeps executing from the .bat file.

Ideally I would like to call start with like a 5 second delay and still keep executing the script and call java. So things as sleep and timeout won't work for me since java won't start as well than.

Does anybody know a way to do this?

Thanks!

kloknibor
  • 55
  • 1
  • 7
  • Possible duplicate of [How to wait in a batch script?](https://stackoverflow.com/questions/735285/how-to-wait-in-a-batch-script) – MotKohn Jul 10 '17 at 16:57
  • No this is not the case since that will pause the script but than java is still not started. I'll try subbu's way :)! – kloknibor Jul 10 '17 at 17:44

3 Answers3

5

This is basically Magoo's answer, but without the extra batch file. I also add the /B option to the initial START command - there is no need for a second console to appear.

@echo off
start "" /b cmd /c "timeout /nobreak 10 >nul & start "" http://localhost"
echo java -start_java_program
dbenham
  • 127,446
  • 28
  • 251
  • 390
2
start "" delayedstart.bat 10 http://localhost

Where delayedstart.bat is

@echo off
setlocal
timeout /t %1 >nul
start "" %2

I haven't tried it, but it should work...

Magoo
  • 77,302
  • 8
  • 62
  • 84
1

If you use the "start" it would start a new command window

eg.,

start java -start_java_program

then you can wait for a desired time eg.,

timeout /T 10

to wait for 10 seconds

then launch your browser

Subbu
  • 2,130
  • 1
  • 19
  • 28