How can I unblock from a Java started process?

前端 未结 8 1068
旧巷少年郎
旧巷少年郎 2021-01-29 01:27

When executing some command(let\'s say \'x\') from cmd line, I get the following message: \"....Press any key to continue . . .\". So it waits for user input to unblock.

8条回答
  •  盖世英雄少女心
    2021-01-29 02:04

    I wrote an answer to command line execution at this stackoverflow question.

    Yours is a bit more tricky since you probably need to reply.

    In your case it might me necessary to give the input stream gobbler something like a reply channel:

     StreamGobbler outputGobbler = new StreamGobbler(
                                        proc.getInputStream(), "OUTPUT", 
                                        proc.getOutputStream());
    

    and make it match a pattern and reply on the given input stream.

    while ((line = br.readLine()) != null) {
        System.out.println(type + ">" + line);
        if (line.contains(PRESS_KEY_CONTINUE) {
            ostream.write("y".getBytes("US-ASCII")); 
            System.out.println("< y"); 
        }
    }
    

    Hope this helps.

提交回复
热议问题