자바 에서 Runtime 에서 Linux 를 실행 하 는 방향 을 바 꾸 는 해결 방법 을 호출 합 니 다.

2988 단어
일반적으로 리 눅 스에 서 리 셋 명령 을 직접 실행 하 는 것 은 문제 가 없다.하지만 자바 의 Runtime 클래스 를 통 해 명령 을 실행 할 때 성공 하지 못 했 습 니 다.
보통 두 가지 해결 방법 이 있다.
방법 1:
     Runtime.exec()     Process         。
		Process process = runtime.exec(command);
		InputStreamReader is = new InputStreamReader(process.getInputStream());
		BufferedReader br = new BufferedReader(is);
		String line = null;
		while((line = br.readLine())!=null){
			System.out.println(line); 
		}

파일 출력 을 통 해 로 컬 로 출력 할 수도 있 습 니 다.
방법 2:
직접 실행:
Runtime.getRuntime().exec(mysqldump -uusername -ppassword -hhost -P1800 --databases gxt_main_db --tables mac_summary --no-create-info --where='mac=52242000447'  >>/home/workspace/test/files/sql_files/mac_summary.sql);

결과 가 나 오지 않 을 것 이다.
exec 는 리 셋 과 파이프 기 호 를 추가 할 수 없 기 때문이다.
다음 과 같이 실행 하도록 변경 하 다
String[] command = {"sh","-c","mysqldump -uusername -ppassword -hhost -P1800 --databases gxt_main_db --tables mac_summary --no-create-info --where='mac=52242000447'  >>/home/workspace/test/files/sql_files/mac_summary.sql"}

Runtime.getRuntime().exec(command)

문 제 는 해 결 될 수 있다!

좋은 웹페이지 즐겨찾기