Home > Uncategorized > How to execute shell commands using Java?

How to execute shell commands using Java?


Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method.

An application cannot create its own instance of this class.

import java.util.*;
.
.
.
try {
Runtime rt=new getRunTime(); //This will create an instance of the current system run time.
Process proc=rt.exec(""); //This will execute the desired command.
proc.waitFor();//will wait for the process to end.
}
catch(Exception e) {
...
}
...

Now u can execute the shell commands using java…
Automate the testing code with java…
🙂

Categories: Uncategorized Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: