HN-Community
[JAVA] execute command [newbie only] - Printable Version

+- HN-Community (https://hacker-newbie.org)
+-- Forum: Miscellaneous (https://hacker-newbie.org/forum-86.html)
+--- Forum: Coding/Programing (https://hacker-newbie.org/forum-19.html)
+---- Forum: Aplication Programing (https://hacker-newbie.org/forum-39.html)
+---- Thread: [JAVA] execute command [newbie only] (/thread-13698.html)



[JAVA] execute command [newbie only] - Dika_xb - 05-09-2012

java
lagi belajar java akuuu Ngakak

gimana kalo java bsa mengexecute command2,baik itu di windows ato pun di linux

nyokkkk codinggggggggg

Code:
import java.io.*; /** * * @author xb */ public class Main { public static void main(String[] args) { // TODO code application logic here try{ String cmd ="cmd /c dir"; // Stringcmd ="ls -la"; Runtime run = Runtime.getRuntime(); Process pr = run.exec(cmd); BufferedReader br = new BufferedReader(new InputStreamReader(pr.getInputStream())); String line=""; while((line = br.readLine()) !=null) { System.out.println(line); } }catch(Exception e) { System.out.println(e); } } }
Piktor

gatau gmn mau jelasinnya Ngakak
yg mau coba ,mari di selidiki scriptsnya

cmd di atas untuk menampilkan list file dan folder
Watados[/code]


RE: [JAVA] execute command [newbie only] - Neo_HNc - 05-09-2012

ane biasa gini om.. cek os dulu.. klo "win" baru di exec.. CMIIW


PHP Code:
public static void main(String[] args) { String os = System.getProperty("os.name").toLowerCase(); if (os.indexOf("win") == 0) { try { Process p = Runtime.getRuntime().exec("cmd /c ipconfig"); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; while ((line = br.readLine()) != null) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } } }



RE: [JAVA] execute command [newbie only] - lanionk - 10-06-2012

hadeuh..
keliatan sederhana..tapi ko mumet ya ? Watados