Example usage for java.lang Process wait

List of usage examples for java.lang Process wait

Introduction

In this page you can find the example usage for java.lang Process wait.

Prototype

public final native void wait(long timeoutMillis) throws InterruptedException;

Source Link

Document

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

Usage

From source file:org.mzd.shap.analysis.metagene.Metagene2008ToXML.java

public static void main(String[] args) throws IOException, BeanIOException {
    if (args.length != 2) {
        System.out.println("[input sequence] [output orfs]");
        System.exit(1);/*from  ww  w.jav  a 2  s  .c  om*/
    }

    Process p = Runtime.getRuntime().exec("metagene " + args[0]);
    try {
        synchronized (p) {
            StringWriter sw = new StringWriter();
            InputStreamReader isr = new InputStreamReader(p.getInputStream());
            int retVal;
            while (true) {
                p.wait(100);
                while (isr.ready()) {
                    sw.write(isr.read());
                }
                try {
                    retVal = p.exitValue();
                    break;
                } catch (IllegalThreadStateException ex) {
                    /*...*/}
            }

            // Just make sure stdout is completely empty.
            while (isr.ready()) {
                sw.write(isr.read());
            }

            if (retVal != 0) {
                System.out.println("Non-zero exist status [" + retVal + "]");
                InputStream is = null;
                try {
                    is = p.getErrorStream();
                    while (is.available() > 0) {
                        System.out.write(is.read());
                    }
                } finally {
                    if (is != null) {
                        is.close();
                    }
                }
            } else {
                new Metagene2008ToXML().convert(sw.toString(), new File(args[1]));
            }

            System.exit(retVal);
        }
    } catch (InterruptedException ex) {
        /*...*/}
}

From source file:patientmanagerv1.HomeController.java

public void launchSpeechRecognition() {
    Runtime rt = Runtime.getRuntime();
    try {/*from  w  w  w. j a  va 2 s  . co  m*/
        //Process process = rt.exec("control panel");
        //Process process2 = rt.exec("cmd.exe");
        Process process = rt.exec("Control Panel");

        try {
            process.wait(2500);
        } catch (Exception e) {
        }

        Process process3 = rt.exec("notepad");

        //Process process4 = rt.exec("Speech Recognition");

    } catch (Exception e) {
        //    System.out.println(e);
    }

    try {
        Audio audio = Audio.getInstance();
        InputStream sound = audio.getAudio("Type 'speech' into the control panel search bar.",
                Language.ENGLISH);
        audio.play(sound);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null,
                "Type 'Speech' into the control panel search bar. It will guide you through how to use Windows 7 Native Dictation");
    }

}