자바 에서 Runtime 에서 Linux 를 실행 하 는 방향 을 바 꾸 는 해결 방법 을 호출 합 니 다.
보통 두 가지 해결 방법 이 있다.
방법 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)
문 제 는 해 결 될 수 있다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.