this post에서 통찰력을 얻으려면 우분투에서 다른 프로그램 (C++ 프로그램)을 실행해야하는 Java 프로그램이 있어야합니다. 결과가 null인지 확인하기 위해 이미 실행 중인지 확인해야합니다 (ps -A | grep 'test'
). 원하는 프로그램을 실행하는 명령은 다음과 같습니다 : ./src/test -w -b -f tracefiles/trace111.txt -z
. 내 Java 프로그램이 현재 어떤 디렉토리에 있더라도 어떻게 할 수 있습니까? 불행히도 내 자바 프로그램이이 오류를 보여줍니다 : No such file or directory
내 자바 클래스 파일의 동일한 디렉토리에서 터미널에서 동일한 명령을 실행하는 동안, 그것을 실행합니다. 당신은 당신의 PATH 변수에 자바 빈 방향을 추가 할 필요가우분투에서 다른 프로그램을 실행하는 Java 프로그램
import java.io.*;
public class JavaRunCommand {
public static void main(String args[]) {
String s = "./../../../Downloads/yse.wzt/src/yse4 -w -b -f ../../../Downloads/yse.wzt/tracefiles/capacity.10MbpsUP_1MbpsDown_400RTT_PER_0.0001.txt -z -at=eth0 -an=eth1";
try {
// run the Unix "ps -ef" command
// using the Runtime exec method:
Process p = Runtime.getRuntime().exec(s);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(
p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(
p.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
System.out
.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
System.exit(0);
} catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}
}
}
이 답변은 진짜 질문과 아무런 관련이 없습니다. –
문제는 JAVA가 경로 상에 있지 않으므로 프로그램이 실패한 것입니다. 그게 어떻게 관련이 없습니까? –
사실 이들은 기본적입니다! 그것은 이미 끝났어. –