이 프로그램이 있습니다
import java.io.IOException;
public class ShellCommand {
public void execShellCmd(String cmd) throws IOException{
Runtime.getRuntime().exec(new String[] {"gnome-terminal", "-x", "bash", "-c", cmd});
}
}
cmd는 다음과 같은 매개 변수를 포함하는 문자열입니다.
/home/fireworks/workspace/ABT/hello.sh
hello.sh는 자바에서 실행할 sh 파일입니다.
프로그램은 그놈 터미널을 연 후 정상적으로 그놈 터미널이 닫힐 때까지 기다리지 않고 계속 작동합니다.
이미 방법을 시도 waitFor();
했지만 아무것도 변경되지 않았습니다.
프로그램이 그놈 터미널이 닫힐 때까지 기다릴 수있는 솔루션이 있습니까?
해결 : 우분투 15의 그놈 터미널이 문제입니다. 나는 xterm을 사용한다
다음은 나를 위해 작동합니다.
import java.io.IOException;
public class ShellCommand {
public void execShellCmd(String cmd) throws IOException, InterruptedException {
Process p = Runtime.getRuntime().exec(new String[] {"gnome-terminal", "-x", "bash", "-c", cmd});
System.out.println( "Started proc" );
p.waitFor();
System.out.println( "Done waiting" );
}
public static void main( String[] args ) {
ShellCommand s = new ShellCommand();
try {
s.execShellCmd( "sleep 10; echo done" );
} catch( Exception e ) {
}
}
}
"started proc"출력물이 표시되고 터미널이 완료 될 때까지 기다린 다음 "Done waiting"이 표시됩니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다