2 개의 인수로 명령 행 프로그램을 실행해야합니다. 그러나 작업 디렉토리에서 실행해야합니다. 즉, "c : \ folder \ subfolder \ command arg1 arg2"가 아닌 "command arg1 arg2"입니다.Java의 특정 작업 디렉토리에서 명령 행 프로그램을 실행해야합니다.
여기 다른 질문에서 Runtime.exec (cmdArray, null, workingDirectory)를 사용했습니다. 하지만 난 계속 "CreateProcess 오류 = 2, 시스템은 지정된 파일을 찾을 수 없습니다". 나는 검사했고, 경로와 파일이 모두 존재하므로, 무엇이 잘못 될지 모른다. 여기에 제가 사용하고있는 코드가 있습니다.
String [] fileName = {"mp3wrap.exe", "Clear_10", "*.mp3"};
String dirName = "E:\\Music\\New Folder\\zz Concatinate\\Clear_10";
try {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(fileName, null, new File(dirName));
BufferedReader input = new BufferedReader(new InputStreamReader
(pr.getInputStream()));
String line = null;
while ((line = input.readLine()) != null) {
System.out.println(line);
}//end while
int exitVal = pr.waitFor();
System.out.println("Exited with error code " + exitVal);
}//end try
catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}//end catch`
이 오류를 받고 있어요 :
때 java.io.IOException : 프로그램 "mp3wrap.exe"를 실행할 수 없습니다 (디렉토리에 "E : 음악 \ 새 폴더 \의 ZZ Concatinate \ Clear_10 \") : CreateProcess error = 2, 지정한 파일을 찾을 수 없습니다.
전체 경로 지정 하시겠습니까? 당신은 정교한 pl 수 있습니까? –
@Zedai : Windows의 경우 "C : \\ 프로그램 \\ 도구 \\ 오디오 \\ 가입 \ 부품 \\ 플레이어 \\ mp3wrap.exe"또는 이와 비슷한 것입니다. 예를 들어 Linux의 경우 "/ usr/local/bin/mp3wrap"입니다. –
질문을 다시 읽고 내 대답을 연장하십시오. –