Post

ProcessBuilder를 사용하여 python 파일을 실행할 때 Process exited with code 9009

ProcessBuilder를 사용하여 python 파일을 실행할 때 Process exited with code 9009

원인

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
builder = new ProcessBuilder("python", substring, String.valueOf(surveyDocumentId));

builder.redirectErrorStream(true);
Process process = builder.start();

// 자식 프로세스가 종료될 때까지 기다림
int exitCode;
try {
    exitCode = process.waitFor();
} catch (InterruptedException e) {
    // Handle interrupted exception
    exitCode = -1;
}

if (exitCode != 0) {
    BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
    String errorLine;
    System.out.println("Error output:");
    while ((errorLine = errorReader.readLine()) != null) {
        System.out.println(errorLine);
    }
}

System.out.println("Process exited with code " + exitCode);
  • processbulider에 “python” 를 인자로 주어 파이썬 파일을 실행할 때, 시스템은 시스템의 PATH 환경 변수에서 Python 실행 파일을 찾으려고 시도합니다. 이때 문제가 발생하였습니다.

해결 방법

  • 파이썬 재설치
  • PATH 환경 변수를 재설정하여 해결했습니다.
This post is licensed under CC BY 4.0 by the author.