import java.io.*;
public class doscmd
{
public static void main(String args[])
{
try
{
Process p=Runtime.getRuntime().exec("cmd /c dir");
p.waitFor();
BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
while(line!=null)
{
System.out.println(line);
line=reader.readLine();
}
}
catch(IOException e1) {}
catch(InterruptedException e2) {}
System.out.println("Done");
}
}
Here is where I collect snippets and interesting article useful to my job. One of these days I should rewrite it in a more organized way. Duccio Fabbri
martedì 9 ottobre 2012
How to run Windows commands in JAVA and return the result text as a string
http://stackoverflow.com/questions/8963413/how-to-run-windows-commands-in-java-and-return-the-result-text-as-a-string
Iscriviti a:
Commenti sul post (Atom)
Nessun commento:
Posta un commento