java에서 일부 파일을 실행하기 위해 mysql을 실행하려고합니다. 입력 파일에서 읽어와 MySQL의 프로세스에 파이프로 연결하여, 모든게 괜찮아 보이지만 라인waitFor()에서 프로세스가 멈 춥니 다.
int exitCode = proc.waitFor();
는 결코 반환하지 않습니다.
private boolean runScript(String path, String cmd, File file) throws IOException, InterruptedException {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(path + File.separatorChar + cmd);
OutputStream procOS = proc.getOutputStream();
InputStream procES = proc.getErrorStream();
InputStream procIS = proc.getInputStream();
OutputStreamWriter procStdIn = new OutputStreamWriter(procOS);
FileInputStream fis = new FileInputStream(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
String send;
while ((send = reader.readLine()) != null) {
procStdIn.write(send);
System.out.println(send);
copyStream(procES, System.err);
copyStream(procIS, System.out);
}
procStdIn.write("\r\nexit\r\n");
int exitCode = proc.waitFor();
return exitCode == 0;
}
private void copyStream(InputStream is, PrintStream err) throws IOException {
byte b[] = new byte[ 1024 ];
int length;
while (is.available() > 0 && (length = is.read(b)) > 0) {
err.write(b, 0, length);
}
}
당신은 자식 프로세스가 종료 된 것을 볼 수 있습니까? 아마도'copyStream'은'exit'를 쓰고 난 후 마지막으로 한 번해야할까요? –
@Hemal 아직 카드 프로세스가 실행되고 있지 않습니다. – stacker