Runtime.getRuntime().exec() ??

Discussion in 'Java' started by Andrew Regan, Jun 28, 2004.

  1. Andrew Regan

    Andrew Regan Guest

    I'm using Process runner = Runtime.getRuntime().exec( cmdArgs );
    where cmdArgs {"/bin/sh", "-c", <perl program>}.

    If <perl program> is "/opt/vr/bin/show_active_servers" I can get the input
    stream and read what the perl program outputs as follows. In fact it works
    for any of the 4 programs in /opt/vr/bin directory.

    BufferedReader is = new BufferedReader(new
    InputStreamReader(runner.getInputStream()));
    while((line = is.readLine()) != null){
    System.out.println(line);
    }

    However if I change the program to "/opt/vr/etc/vr_report" I can't read any
    of the programs output. No exceptions are thrown. The exit level of the
    process is 0. I have tried inserting waitFors(). The perl programs are all
    chmoded the same and are owned by the same user. I have also tried reading
    from stderror and can't get any of the programs output. I have timed the
    programs and the times seem to indicate that the java program is executing
    the perl program, but I can't read any of its output?

    Any ideas?

    Thanks for your help,
    Andrew Regan
     
    Andrew Regan, Jun 28, 2004
    #1
    1. Advertising

  2. Andrew Regan

    WagnerR Guest

    WagnerR, Jun 28, 2004
    #2
    1. Advertising

  3. Andrew Regan wrote:
    > I'm using Process runner = Runtime.getRuntime().exec( cmdArgs );
    > where cmdArgs {"/bin/sh", "-c", <perl program>}.
    >
    > If <perl program> is "/opt/vr/bin/show_active_servers" I can get the input
    > stream and read what the perl program outputs as follows. In fact it works
    > for any of the 4 programs in /opt/vr/bin directory.
    >
    > BufferedReader is = new BufferedReader(new
    > InputStreamReader(runner.getInputStream()));
    > while((line = is.readLine()) != null){
    > System.out.println(line);
    > }
    >
    > However if I change the program to "/opt/vr/etc/vr_report" I can't read any
    > of the programs output. No exceptions are thrown. The exit level of the
    > process is 0. I have tried inserting waitFors(). The perl programs are all
    > chmoded the same and are owned by the same user. I have also tried reading
    > from stderror and can't get any of the programs output. I have timed the
    > programs and the times seem to indicate that the java program is executing
    > the perl program, but I can't read any of its output?
    >
    > Any ideas?
    >
    > Thanks for your help,
    > Andrew Regan
    >
    >

    Have you tried reading the error stream?
    I suspect you will find somethig there.

    Steve
     
    Steve Horsley, Jun 28, 2004
    #3
  4. Andrew Regan

    Yu SONG Guest

    "Andrew Regan" <>
    > I'm using Process runner = Runtime.getRuntime().exec( cmdArgs );
    > where cmdArgs {"/bin/sh", "-c", <perl program>}.
    >
    > If <perl program> is "/opt/vr/bin/show_active_servers" I can get the input
    > stream and read what the perl program outputs as follows. In fact it works
    > for any of the 4 programs in /opt/vr/bin directory.
    >
    > BufferedReader is = new BufferedReader(new
    > InputStreamReader(runner.getInputStream()));
    > while((line = is.readLine()) != null){
    > System.out.println(line);
    > }
    >
    > However if I change the program to "/opt/vr/etc/vr_report" I can't read

    any
    > of the programs output. No exceptions are thrown. The exit level of the
    > process is 0. I have tried inserting waitFors(). The perl programs are all
    > chmoded the same and are owned by the same user. I have also tried reading
    > from stderror and can't get any of the programs output. I have timed the
    > programs and the times seem to indicate that the java program is executing
    > the perl program, but I can't read any of its output?
    >
    > Any ideas?


    If "any of the 4 programs in /opt/vr/bin directory" works while
    "/opt/vr/etc/vr_report" don't, I think there may be something wrong with
    your perl programs. (e.g in "/opt/vr/etc/vr_report")

    You can have a look at the differences between these perl programs(i.e.
    methods writing to stdout, some variables, etc.) and see what could happen.


    --
    Song

    /* E-mail.c */
    #define User "Yu.Song"
    #define At '@'
    #define Warwick "warwick.ac.uk"
    int main() {
    printf("Yu Song's E-mail: %s%c%s", User, At, Warwick);
    return 0;}

    Further Info. : http://www.dcs.warwick.ac.uk/~esubbn/
    _______________________________________________________
     
    Yu SONG, Jun 30, 2004
    #4
    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. Zsolt Koppany
    Replies:
    2
    Views:
    7,190
    SaintMagoo
    Mar 5, 2011
  2. MARTIN Herve \(EXT\)
    Replies:
    1
    Views:
    1,476
    Anthony Borla
    Nov 27, 2003
  3. paul brown
    Replies:
    3
    Views:
    5,596
    deepa gr
    Feb 17, 2009
  4. S!mb@
    Replies:
    3
    Views:
    7,696
    Roedy Green
    Jul 19, 2004
  5. Jakir
    Replies:
    4
    Views:
    3,232
    Jakir
    Sep 1, 2004
Loading...

Share This Page