2014-06-15 3 views
-1

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); 
     } 
    } 
} 

답변

0

:

여기 내 간단한 코드입니다. 홈 디렉토리에있는 .bashrc에을 편집하고 다음 행을 추가

export PATH=/path/to/java/bin:$PATH 

당신은 '소스'당신의 .bashrc 파일에 필요하거나 경로을 적용하려면 터미널을 다시 시작합니다. 홈 디렉토리 유형에서 : 우분투에 환경 변수 설정에 대한

source .bashrc 

자세한 정보는 여기에 있습니다 : https://help.ubuntu.com/community/EnvironmentVariables#Persistent_environment_variables.

echo $PATH으로 PATH 지정이 올바른지 확인하거나 java/bin 디렉토리가 아닌 다른 디렉토리에서 javac을 입력하기 만하면됩니다.

+1

이 답변은 진짜 질문과 아무런 관련이 없습니다. –

+0

문제는 JAVA가 경로 상에 있지 않으므로 프로그램이 실패한 것입니다. 그게 어떻게 관련이 없습니까? –

+0

사실 이들은 기본적입니다! 그것은 이미 끝났어. –

관련 문제