Re: Why does this only work when I am running a shellscript

Discussion in 'Java' started by markspace, Mar 30, 2013.

  1. markspace

    markspace Guest

    On 3/30/2013 1:46 AM, Cecil Westerhof wrote:
    > I have the following code:
    > private static void doCommand(final String cmd) throws IOException {
    > Process p;
    > Scanner sc;
    >
    > System.out.println("#" + cmd + "#");
    > p = Runtime.getRuntime().exec(cmd);
    > sc = new Scanner(p.getInputStream());


    Besides Barb's answer, I believe you also have to drain the output
    stream. If you don't read a program's output, it'll hang, waiting for you.
    markspace, Mar 30, 2013
    #1
    1. Advertising

  2. On 3/30/2013 11:23 AM, markspace wrote:
    > On 3/30/2013 1:46 AM, Cecil Westerhof wrote:
    >> I have the following code:
    >> private static void doCommand(final String cmd) throws IOException {
    >> Process p;
    >> Scanner sc;
    >>
    >> System.out.println("#" + cmd + "#");
    >> p = Runtime.getRuntime().exec(cmd);
    >> sc = new Scanner(p.getInputStream());

    >
    > Besides Barb's answer, I believe you also have to drain the output
    > stream. If you don't read a program's output, it'll hang, waiting for you.


    He does attempt to read in a loop.

    Arne
    Arne Vajhøj, Mar 30, 2013
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,693
    Smokey Grindel
    Dec 2, 2006
  2. Barb Knox
    Replies:
    1
    Views:
    250
    Steven Simpson
    Mar 30, 2013
  3. Roedy Green
    Replies:
    0
    Views:
    224
    Roedy Green
    Mar 30, 2013
  4. RVic
    Replies:
    2
    Views:
    239
    Roedy Green
    Apr 1, 2013
  5. Steven Simpson
    Replies:
    0
    Views:
    230
    Steven Simpson
    Mar 30, 2013
Loading...

Share This Page