How to open Command-prompt using java

In this post  i ll be telling you about to opening the Command-Prompt using the Java code that is So simple and easy to Understand its shown as follows..

In this i have not used any kind of GUI  so that for your Purpose you can use the Applet or Swing/Awt as per your need.


public class cmdex

{

public static void main(String[] args)

{

try{

//Create the Process Instance, You don’t need to Import anything for this.

Process p;

//To Execute the Process containg the Command as the Parameter

p = Runtime.getRuntime().exec("cmd /c start cmd");

//As the same way you can use all the commands to Execute your favorite apps.

}catch(Exception e){}

}

}

To Execute the other application like command-prompt, you can use the Following code : =)

To open Calculator use this Line  -> p = Runtime.getRuntime().exec(“cmd /c calc”);

To open Control panel use this Line = p = Runtime.getRuntime().exec(“cmd /c control”);

Output of the Application is as follows :-

Command-Prompt Demo
Command-Prompt Demo

This is how you can also use the different command to execute the other things as shown above.

And i ll be posting the other post on the stuff called “Desk click” with the help of that you can access the most of the Important application(paint,ms word, Control panel, Browser,Internet Properties as well as you can Log off nd Turn off your PC From the Applet only and many more interesting stuff) with just a click from the Java applet very soon…

so till that please provide your feedback or your reviews on this Article and Let me know your ideas..

Thanks & Regards Hitesh Parmar 🙂

Learn , Innovate and Share  🙂

Advertisements

5 thoughts on “How to open Command-prompt using java

  1. hello I was fortunate to search your subject in digg
    your Topics is superb
    I get much in your website really thanks very much
    btw the theme of you website is really magnificentsuper
    where can find it

    1. if you want to work with the opening the command prompt, then there is one box in which i have written the code, on the top-right side you will get the option to copy that code, and use that,

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