태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.


===================   SystemExec1.java    ===================
package test;

public class SystemExec {

 public static void main(String[] args) {

  try {
   Runtime rt = Runtime.getRuntime();
   String[] cmd = { "cmd.exe", "/c",
     "mysqldump -u root -p1234 mysql > mysql.sql" };
   rt.exec(cmd);
   System.out.println(cmd[2]);
   System.out.println("Complete!");

  } catch (Exception e) {
   System.out.println("Error occurred!" + e.toString());
   System.exit(0);
  }
 }
}



=================        SystemExec2.java       ====================

package test;

import java.io.BufferedReader;
import java.io.FileReader;

public class SystemExec2 {
 public static void main(String[] args) {

  try {
   Runtime rt = Runtime.getRuntime();
   String[] cmd = {"c:\\windows\\system32\\cmd", "/c", "dir > ","rs.txt"};
   rt.exec(cmd);
   System.out.println(cmd[2]+cmd[3]);
   FileReader fr = new FileReader(cmd[3]);
   BufferedReader br = new BufferedReader(fr);
   int i =0;
   while((i=br.read()) != -1){
    System.out.print((char)i);
   }
   System.out.println("Complete!");

  } catch (Exception e) {
   System.out.println("Error occurred!" + e.toString());
   System.exit(0);
  }

 }
}






===================   SystemExec3.java     =====================

package test;

import java.io.BufferedReader;
import java.io.FileReader;


public class SystemExec3 {
 public static void main(String[] args) {
  try {
   Runtime rt = Runtime.getRuntime();
   String[] cmd = {"cmd.exe", "/c", "ping www.ssial.com > ","ping.txt"};
   rt.exec(cmd);
   System.out.println(cmd[2]+cmd[3]);
   FileReader fr = new FileReader(cmd[3]);
   BufferedReader br = new BufferedReader(fr);
   int i =0;
   while((i=br.read()) != -1){
    System.out.print((char)i);
   }
   System.out.println("Complete!");


  } catch (Exception e) {
   System.out.println("Error occurred!" + e.toString());
   System.exit(0);
  }
 }
}


 

top

Trackback Address :: http://www.ssial.com/trackback/132 관련글 쓰기

  1. 2008/11/01 22:14 댓글주소 | 수정/삭제 | 댓글

    와~ 이런방법이있었을줄이야..
    c언어보단 어렵네요 살짝 그래도 재밌네요 감사합니다.

Write a comment