Solved

Some system("pause") equivalent in java?

Posted on 2007-11-28
11
10,903 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
Comment Utility
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
Comment Utility
System.in.read();
0
 
LVL 7

Expert Comment

by:UrosVidojevic
Comment Utility
Little correction:

try {
      Thread.sleep(timeInMiliseconds);
} catch (InterruptedException e) {}
0
 
LVL 17

Expert Comment

by:contactkarthi
Comment Utility
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_Cr
Comment Utility
You can simply add 'pause' to your bat file.

    C:\test\java MyApp
    pause

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 92

Expert Comment

by:objects
Comment Utility
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
Comment Utility
(already mentioned that)
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
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
Comment Utility
>>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
Comment Utility
:)
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
:-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to implement Singleton Design Pattern in Java.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now