표준출력 (stdout) : 정상적인 실행 결과.
표준에러 (stderr) : 에러 메시지.
로컬에서 스크립트(script.sh)를 실행하는 경우.
Process process = Runtime.getRuntime().exec("./script.sh");
표준출력(stdOut) 읽어오기. getInputStream()
try (BufferedReader stdOut = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = stdOut.readLine()) != null) {
System.out.println("STDOUT: " + line);
}
} catch (IOException e) {
e.printStackTrace();
}
표준에러(stdErr) 읽어오기. getErrorStream()
try (BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
String line;
while ((line = stdError.readLine()) != null) {
System.out.println("STDERR: " + line);
}
} catch (IOException e) {
e.printStackTrace();
}
'기타' 카테고리의 다른 글
[웹서버] NestJS란 ? (0) | 2025.02.13 |
---|---|
[LINUX/JAVA] 자바 버전 관리 도구 (alternatives) (0) | 2025.02.11 |
[LINUX] 포그라운드/백그라운드 프로세스(nohup, &) (0) | 2025.02.11 |
[Docker] 도커 컨테이너, Dockerfile, Volume, 도커 네트워크 (0) | 2025.02.10 |
[API / Python] Geolocation API_현재 위치좌표 추출 (0) | 2025.02.09 |