This java code will show how can we execute a windows command from Java
package commons.utilities;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ExecuteCommandFromJava {
public static void main(String[] args) throws IOException {
String[] command = new String[3];
command[0] = "cmd";
command[1] = "/c";
command[2] = "E: && dir && cd snap";
Process p = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = reader.readLine();
while (line != null) {
System.out.println(line);
line = reader.readLine();
}
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String Error;
while ((Error = stdError.readLine()) != null) {
System.out.println(Error);
}
while ((Error = stdInput.readLine()) != null) {
System.out.println(Error);
}
}
}
package commons.utilities;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ExecuteCommandFromJava {
public static void main(String[] args) throws IOException {
String[] command = new String[3];
command[0] = "cmd";
command[1] = "/c";
command[2] = "E: && dir && cd snap";
Process p = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = reader.readLine();
while (line != null) {
System.out.println(line);
line = reader.readLine();
}
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String Error;
while ((Error = stdError.readLine()) != null) {
System.out.println(Error);
}
while ((Error = stdInput.readLine()) != null) {
System.out.println(Error);
}
}
}
Source for this information : http://www.javaquery.com/2011/03/how-to-execute-multiple-command-in.html
They were impressed with their resourcefulness,what is a design firm collaborative approach to development, and extensive technical knowledge.
ReplyDeleteThe writer understand better the mind of people what they want to learn through their writing therefore this article is outstanding. Thanks!!!
ReplyDeleteurl opener free tool
If your system used a torsion spring, you need to call in a professional. This is because such a garage entrance opener is large and mounted over the door and you may hurt yourself while trying to perform the garage door repair. emergency garage door repair
ReplyDeleteI was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up.
ReplyDeleteEmergency Garage Door Repair
This specific seems to be definitely excellent. These very small facts are produced using wide range of qualifications know-how. I favor the idea a good deal Smart contract developer in new delhi
ReplyDeletegreat post Keep it up thanks for sharing
ReplyDeleteBlockchain Software Development Services
This article is unique and interesting. thanks for your share.
ReplyDeleteAuto pool MLM Software in Surat
Awesome idea its very informative thank you so much.gupt rog doctors in allahabad
ReplyDeleteWonderful post I really appreciate your blog..... Best Sexologist in Prayagraj
ReplyDeleteIt is really a fascinating blog. gupt rog in allahabad
ReplyDelete