Solved

Some system("pause") equivalent in java?

Posted on 2007-11-28
11
12,112 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:DJ_AM_Juicebox
  • 4
  • 2
  • 2
  • +2
11 Comments
 
LVL 7

Expert Comment

by:UrosVidojevic
ID: 20368439
You can use

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

If you want to pause for some time.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 20368443
System.in.read();
0
 
LVL 7

Expert Comment

by:UrosVidojevic
ID: 20368450
Little correction:

try {
      Thread.sleep(timeInMiliseconds);
} catch (InterruptedException e) {}
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 17

Expert Comment

by:contactkarthi
ID: 20368464
you can have a Thread.sleep of(5000)

so that it waits for 5 sec..

you can increase the value
0
 
LVL 13

Expert Comment

by:Bart Cremers
ID: 20368480
You can simply add 'pause' to your bat file.

    C:\test\java MyApp
    pause

0
 
LVL 92

Expert Comment

by:objects
ID: 20369118
theres no way to achieve that, best you can do is pause until user hits enter key using

System.in.read();
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20369145
(already mentioned that)
0
 
LVL 92

Expert Comment

by:objects
ID: 20369205
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 :)

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20369231
>>you comment was wrong, and won't achieved what has been asked.

Strange that you repeated it then ... ;-)
0
 
LVL 17

Expert Comment

by:contactkarthi
ID: 20371258
:)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20371762
:-)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
session migration servlets 2 42
Tomcat: Unable to run tomcat service. 2 24
eclipse buid path vs tomcat lib path 10 34
Adding multiple JVM environments to RedHat 6 7 49
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question