C, C++, Python 등의 코드를 실행하는 JavaFx에서 IDE 관련 프로그램을 만들고 있습니다. 그리고 사용자 코드에 컴파일 타임/런타임 오류가있는 경우 팝업 창에 스택 오버플로 관련 오류 응답이 표시됩니다. 그러나 오류가 있는지 여부는 어떻게 알 수 있습니까?Java에서 프로세스의 결과가 오류인지 여부를 확인하는 방법은 무엇입니까?
내 코드는 여기에있다 -
public BufferedReader buildCode(File file)
{
String dirname = file.getParent();
String filePath = file.getPath();
String fileName = file.getName();
String objectFileName = FilenameUtils.removeExtension(fileName);
String command = "gcc " + filePath + " -o " + dirname + "/" + objectFileName;
BufferedReader stdInput;// = new BufferedReader(null);
try
{
Process process = Runtime.getRuntime().exec(command);
stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader stdErr = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String compileResult;
while ((compileResult = stdInput.readLine()) != null)
System.out.println(compileResult);
while ((compileResult = stdErr.readLine()) != null)
System.out.println(compileResult);
return stdInput;
}
catch (IOException io)
{
//noinspection ThrowablePrintedToSystemOut
System.out.println(io);
return null;
}
}
내가이 null인지 아닌지, 내가 stdErr
을 확인 같은 것을해야 할 것 같아요. 그러나 나는 아무런 에러가 없으면 EOF
을 stdErr
에 할당했다는 것을 확신하지 못합니다.