2013-09-03 1 views
0

java를 사용하여 Prom (프로세스 마이닝 도구)을 열려고합니다. 그러나 그것은 전혀 효과가 없습니다.java를 사용하여 exe 응용 프로그램을 열 수 없습니다.

try { 
     new ProcessBuilder("c:\\Program Files\\Prom\\prom.exe").start() ; 

       } catch (Exception e) { 
     System.out.println(e); 
     e.printStackTrace(); 
    } 

이 코드는 적용되지 않습니다.

하지만 난 동일한 코드와 동일한 폴더에 UNINST.EXE 열 때,이 일이 왜 모르겠어요 완벽하게

try { 
     new ProcessBuilder("c:\\Program Files\\Prom\\uninst.exe").start() ; 

       } catch (Exception e) { 
     System.out.println(e); 
     e.printStackTrace(); 
    } 

작동합니다. 어떤 해결책이 있습니까? 자바가 무거운 응용 프로그램을로드 할 수 없습니까?

+2

prom.exe를 실행하는 동안 오류나 예외가 발생합니까? –

+1

prom.exe – JNL

답변

4

프로그램 출력이 Process.getInputStream()Process.getErrorStream()을 통해 확인해야합니다. 예외가 발생하지 않는 경고 또는 오류 메시지가 프로그램에서 발생할 수 있습니다. 이러한 오류 또는 경고는 일반적으로 누락 된 경로, 환경 변수, 파일 및 폴더에 대한 사용 권한 또는 누락 된 인수에 대한 것입니다.

Process proc = new ProcessBuilder(
        "c:\\Program Files\\Prom\\prom.exe").start() ; 

    BufferedReader stdInput = new BufferedReader(new 
     InputStreamReader(proc.getInputStream())); 

    BufferedReader stdError = new BufferedReader(new 
     InputStreamReader(proc.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); 
    } 

또한 항상 Process.exitValue()를 사용하여 프로세스의 리턴 코드를 확인하십시오. 관례 상, 0은 모든 것이 OK가되었음을 의미합니다.

+2

+1을 실행할 수있는 권한이 있는지 확인하십시오. Process.waitFor()는 유용 할 수 있습니다 ... – Jayan

+1

나는 그 대답을 편집했으나, 편집은 비 승인되었다고 생각합니다. ... 당신은'Process.getOutputStream()'을 통해 프로그램 출력을 체크하지 않는다 ... 당신은 당신의 코드 예제에서 그렇게 생각한다. 어쨌든 ... +1. – mike

+0

@mike 나 자신이 편집했습니다. 제안 해 주셔서 감사합니다. –