Link to home
Start Free TrialLog in
Avatar of DJ_AM_Juicebox
DJ_AM_Juicebox

asked on

Some system("pause") equivalent in java?

Hi,

Under win32, I wanted to make a bat file that runs my java application. Right now I have to do something like:

    C:\test\java MyApp

but then of course the console window disappears after execution. Is there anyway to keep the console window up until I hit a key to dismiss it? When programming for win32 in C++ I can just use:

     system("pause");

Thanks
Avatar of UrosVidojevic
UrosVidojevic
Flag of Serbia image

You can use

try {
      Thread.sleep(timeInMiliseconds);
} catch (InterruptedException) {}

If you want to pause for some time.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Little correction:

try {
      Thread.sleep(timeInMiliseconds);
} catch (InterruptedException e) {}
you can have a Thread.sleep of(5000)

so that it waits for 5 sec..

you can increase the value
You can simply add 'pause' to your bat file.

    C:\test\java MyApp
    pause

theres no way to achieve that, best you can do is pause until user hits enter key using

System.in.read();
(already mentioned that)
you comment was wrong, and won't achieved what has been asked.
stdin is buffered so as I mentioned above the best you can do is pause until enter is pressed.

System.out.println("Please press Enter to terminate...");
System.in.read();

DJ_AM_Juicebox,

Let me know if you have any questions :)

>>you comment was wrong, and won't achieved what has been asked.

Strange that you repeated it then ... ;-)
:-)