Jun 212012
 

Assalamu’ alaikum wr wb

Kali  ini kita akan mebuat sebuah script untuk mengeksekusi command dalam source java.

/*
*
* Desain by t-team
* email   : mbahsomo@do-event.com
* website : http://www.do-event.com
* ===============================================================
*     Semua sorce dalam program ini dibawah license [GPL]
*     Silakan Untuk mengembangkan dan memperbanyak source ini
*     Dengan tidak menghilangkan nama pembuat
* ===============================================================
*/
package tproject.util;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
*
* @author sugik
*/
public class execToString {
public execToString(String cmdline) {
try {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(cmdline);
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = null;
while ((line = input.readLine()) != null) {
System.out.println(line);
}
int exitVal = pr.waitFor();
System.out.println("Exited with error code " + exitVal);
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}
public static void main(String[] arg) {
new execToString("ping google.com");
}
}

Wassalamu’ alaikum wr wb

Facebook Comments

  One Response to “Execute command from java”

  1. Mas Sugik,

    Saya juga nulis ttg hal diatas disini

    Rgds,
    Afif

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)