blog
[Java] ProcessBuilder waitFor() error code 1 본문
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
String cmd[] = new String[] {"나의", "커맨드", "명령어"};
ProcessBuilder builder = new ProcessBuilder(cmd);
try {
Process process = builder.start();
int exitVal = process.waitFor(); // wait for end of child process
System.out.println("\nExited with error code : " + exitVal);
if (exitVal != 0) {
System.out.println("SUB PROCESS ABNORMAL TERMINATION");
return result;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return result;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return result;
}
|
cs |
Exited with error code : 1
일반 오류여서 헤맸는데...outputstream을 읽어주지 않아 발생한 오류였다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
String cmd[] = new String[] {"나의", "커맨드", "명령어"};
ProcessBuilder builder = new ProcessBuilder(cmd);
try {
builder.redirectErrorStream(true);
Process process = builder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null)
System.out.println("tasklist: " + line);
process.waitFor();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return result;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return result;
}
|
cs |
이렇게 고쳐서 해결
참고 :
https://stackoverflow.com/questions/5483830/process-waitfor-never-returns
https://d2.naver.com/helloworld/1113548
'Web > SpringBoot' 카테고리의 다른 글
[Java] 파일 구분자 (File Separator) (0) | 2022.09.14 |
---|---|
[JPA] nativeQuery where in() 사용 (0) | 2022.09.14 |
[Java] StringBuilder로 JSON value를 만들 때 주의점 (0) | 2022.09.14 |
[Spring Boot] JPA @Query (0) | 2022.03.23 |
[Spring Boot] JPA 테이블 대문자 (0) | 2022.03.23 |