2013-07-23 3 views
0

나는 내가이 코드를 실행 한 후 ProcessBuilder를생산 오류 .exe를 :: 디렉터리 이름이 잘못되었습니다

public class HMetis { 
    private String exec_name = null;  
    private String[] hmetis_args = {"hmetis.exe", "null", "2", "1", "10", "1", "1", "1", "0", "0"}; 

    private Path path; 
    private File file; 

    public HMetis(String hgraph_exec, String hgraph_file) { 
     this.exec_name = hgraph_exec;  
     this.hmetis_args[1] = hgraph_file; 
    }  

    public void runHMetis() throws IOException {  
     this.path = Paths.get("C:\\hMetis\\1.5.3-win32"); 
     this.file = new File(path+"\\"+this.exec_name+".exe");  

     ProcessBuilder pb = new ProcessBuilder(this.hmetis_args); 
     pb.directory(this.file); 

     try {  
      Process process = pb.start();      
     } finally { 
      // do nothing 
     } 
    } 
} 

를 사용하여 기본 Windows .exe 파일을 실행하려면 다음 Java 코드를 메시지에서 디렉토리 이름이 완전히 형성되고 OK 인 것처럼 보이지만 아래 오류가 발생합니다 !! 어떤 제안을 해주시겠습니까?

Cannot run program "hmetis.exe" (in directory "C:\hMetis\1.5.3-win32\hmetis.exe"):CreateProcess error=267, The directory name is invalid 
+0

실행 파일 이름을 디렉토리 경로에 추가하는 것 같습니다. –

+3

[Java ProcessBuilder를 사용하여 여러 인수가있는 Windows .exe 파일을 실행하면 예상대로 출력 파일이 생성되지 않습니다.] (http://stackoverflow.com/questions/17809295/running-windows-exe-file-with-multiple- arguments-using-java-processbuilder-is-n) 같은 문제에 대해 새로운 질문을 시작하는 대신 이전 질문을 수정하십시오. 당신은 또한 당신에게 내 조언의 1sat 포인트를 무시한 것 같습니다. 그렇다면이 중복 질문은 왜 다른 것입니까? –

+0

@Andrew는 중복되지 않습니다. 서로 다른 관찰을하는 두 가지 사례입니다. 이전에 묻는 질문에 아마도 .exe 파일은 오류 메시지를 생성하지 않고 실행 중이지만 .exe 파일은 예상대로 작동하지 않습니다. – joarderm

답변

1

는 :

this.file = new File(path+"\\"+this.exec_name+".exe");  
ProcessBuilder pb = new ProcessBuilder(this.hmetis_args); 
pb.directory(this.file); 
        ^
        | 
        ++++++++ "C:\hMetis\1.5.3-win32\hmetis.exe" 
          should be "C:\hMetis\1.5.3-win32" 

그러나, 당신은

pb.directory(this.path.toFile()); 

같은 작업 디렉토리 만 설정하려면

또한, ProcessBuilder.directory()은 "작업 디렉토리"를 예상대로 설정할 수 없습니다. 적어도 executab을 찾지 않아야합니다. 르. 유사한 문제는 ProcessBuilder can't find file?!에 설명되어 있습니다. 적어도 Windows에서는 현재 작업 디렉토리에있는 실행 파일이 보통 먼저 발견됩니다 (유닉스는 다른 것입니다).

쉽게 수정

String[] hmetis_args = {"C:\\hMetis\\1.5.3-win32\\hmetis.exe", "null", "2", "1", "10", "1", "1", "1", "0", "0"}; 

도 참조

+0

pb.directory()는 File 객체를 기대하므로 pb.directory를 설정합니다 (this.path)는 오류 – joarderm

+1

을 생성합니다.'Path' 객체를'File'으로 변환 할 수 있습니다 - 업데이트 된 답변을보십시오. 아마도 더 쉬운 해결책은'File' 객체를 직접 사용하는 것입니다. File 객체는 path.toFile()을 덮은 후에 –

+0

디렉토리를 나타낼 수 있습니다. 다음 오류가 발생합니다 : 스레드 "main"java의 예외 .io.IOException : 프로그램 "hmetis.exe"("C : \ hMetis \ 1.5.3-win32"디렉토리)를 실행할 수 없습니다. CreateProcess error = 2, 시스템이 업데이트 된 응답과 관련하여 지정된 파일 – joarderm

0

당신은
pb.directory(this.file.getParentFile());
pb.directory(this.file);
를 교체하려고 했습니까? 당신은 ProcessBuilder를의 작업 디렉토리와 같은 실행 파일의 전체 경로를 사용하는

+0

pb.directory()가 File 객체를 필요로하므로 pb.directory (this.path)가 아래 오류를 생성 할 때 제안한대로 – joarderm

+0

오류를 생성합니다. ProcessBuilder 유형의 메소드 디렉토리 (File)는 적용 할 수 없습니다 arguments (String) – joarderm

관련 문제