How can I run commands on a console from Java program?
-
I know how to read inputs from a console and to write output on the console. But I can't find a way to put some commands on a console and run the command. Is there some APIs or something that does those kind of things? Any advice would be appreciated.
-
Answer:
Actually I've found a solution. Using Runtime class, I could solve the problem. http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Runtime.html example: delete a file "aaa" class test { ããpublic static void main(String []args) { ãããtry { ãããããRuntime.getRuntime().exec(ârm aaaâ); ãããããSystem.exit(0); ããã} catch(Exception e) { ãããããSystem.exit(1); ããã} ã} }
Takumi Kato at Quora Visit the source
Related Q & A:
- How can I run all my selenium tests sequentially in C#?Best solution by Stack Overflow
- How can I run CMD command?Best solution by Super User
- How can I transfer video from a dvr box to a computer?Best solution by Yahoo! Answers
- How can I print wirelessly from a laptop to a printer without a router?Best solution by answers.yahoo.com
- How can I run faster?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.