Unable to perform any action before Process.Runtime.exec statement line에 대한 질문을 참조하면 GUI를 업데이트 할 수 없으므로 다음과 같이 외부 코드를 실행하는 코드가있는 스레드 클래스 CmdExec을 두 부분으로 변경했습니다.프로세스를 실행할 때 (SwingUtilities.invokeLater)
public class CmdExec extends Thread
{
private String cmd;
private File path;
public CmdExec() {
}
public CmdExec(String cmd, File path) {
this.cmd = cmd;
this.path = path;
}
public void run(){
try
{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd , null, path);
InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
System.out.println("<ERROR>");
while ((line = br.readLine()) != null)
System.out.println(line);
System.out.println("</ERROR>");
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
} catch (Throwable t)
{
t.printStackTrace();
}
과 대답을 jtahlborn 참조하여, 나는 아래뿐만 아니라 GUI 업데이트 목적으로 또 다른의 Runnable 클래스를했을 :
내가 SwingUtilities.invokeLater에 전화
Runnable doWorkRunnable = new Runnable() {
public void run() {
System.out.println("hello world");
btnTranscribe.setEnabled(false);
areaOutput.setEditable(false);
areaOutput.setEnabled(false);
areaOutput.setText("Performing segmentation, please wait till process is done\n"); }
};
실제로 프로세스를 실행하기 전에 GUI를 변경하려면 외부를 호출하는 .exec() 프로그램은 아래와 같이 표시됩니다 :
SwingUtilities.invokeLater(doWorkRunnable);
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd , null, path);
위의 모든 코드와 함께, GUI는 여전히 업데이트하지 못하고 프로세스가 완료된 후에 만 업데이트됩니다. 이 두 runnable 및 thread를 조정하는 특정 단계에서 잘못 되었습니까?
여러분의 많은 도움에 미리 감사하고 답변
P/S :
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
strSegment = "java -Xmx2024m -jar ./LIUM_SpkDiarization-4.2.jar/--fInputMask=" + strAudioOut + "/%s.wav"
+ " --sOutputMask=" + strCtlOut + "/%s.ctl --sOutputFormat=ctl -- doCEClustering --cMinimumOfCluster=1 new3_20110331103858";
CmdExec tryDemo = new CmdExec();
tryDemo = new CmdExec(strSegment, fSegment);
tryDemo.run();
strExtract = "./sphinx_fe -i " + strAudioOut + "/new3_20110331103858.wav"
+ " -o " + strFeatureOut + "/new3_20110331103858.mfc";
//System.out.println (strExtract);
//executeCommand (strExtract, fExtract);
tryDemo = new CmdExec(strExtract, fExtract);
tryDemo.run();
}
CmdExec 스레드를 시작할 코드를 표시 할 수 있습니까? – jtahlborn
안녕하세요 jtahlborn, 위의 mian contentn에 코드를 첨부했습니다. GUI에서 버튼을 누를 때 트리거되는 이벤트입니다.) = – striky