Trouble providing multiple input to a Command using Apache Commons Exec and extracting output

前端 未结 3 2161
孤街浪徒
孤街浪徒 2021-01-02 13:05

I am writing a Java application that needs to use an external command line application using the Apache Commons Exec library. The application I need to run has a fairly lon

3条回答
  •  情书的邮戳
    2021-01-02 13:31

    For my purposes, it turns out I only needed to override the "ExecuteStreamHandler". Here is my solution, which captures stderr into a StringBuilder, and allows you to stream things to stdin and receive things from stdout:

    class SendReceiveStreamHandler implements ExecuteStreamHandler
    

    You can see the whole class as a gist on GitHub here.

提交回复
热议问题