Java Runtime getRuntime().exec not work in AIX

Discussion in 'Java' started by SamuelXiao, Sep 22, 2011.

  1. SamuelXiao

    SamuelXiao Guest

    Hi All,

    I have a Java program that needs to run a command in AIX environment.
    The code is as follows:

    String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log |
    mailx -s 'Testing' "};
    Process process = Runtime.getRuntime().exec(cmds);

    But I found that it does not work, the cmd is fine because I have
    tried it in AIX without using these code. It seems that AIX does not
    allow the process to be created?

    Does anyone know if there is any configuration to allow it in AIX? I
    have also post this question in the AIX forum.

    Any help would be highly appreciated.
     
    SamuelXiao, Sep 22, 2011
    #1
    1. Advertising

  2. SamuelXiao

    Daniel Pitts Guest

    On 9/22/11 8:09 AM, SamuelXiao wrote:
    > Hi All,
    >
    > I have a Java program that needs to run a command in AIX environment.
    > The code is as follows:
    >
    > String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log |
    > mailx -s 'Testing' "};
    > Process process = Runtime.getRuntime().exec(cmds);
    >
    > But I found that it does not work, the cmd is fine because I have
    > tried it in AIX without using these code. It seems that AIX does not
    > allow the process to be created?
    >
    > Does anyone know if there is any configuration to allow it in AIX? I
    > have also post this question in the AIX forum.
    >
    > Any help would be highly appreciated.

    Read the javadocs for process. You need to have something reading the
    stdout/stderr, or they may block when the buffer fills.

    Also, consider using ProcessBuilder instead.

    <http://download.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html>
     
    Daniel Pitts, Sep 22, 2011
    #2
    1. Advertising

  3. SamuelXiao

    Arne Vajhøj Guest

    On 9/22/2011 11:09 AM, SamuelXiao wrote:
    > I have a Java program that needs to run a command in AIX environment.
    > The code is as follows:
    >
    > String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log |
    > mailx -s 'Testing' "};
    > Process process = Runtime.getRuntime().exec(cmds);
    >
    > But I found that it does not work, the cmd is fine because I have
    > tried it in AIX without using these code. It seems that AIX does not
    > allow the process to be created?
    >
    > Does anyone know if there is any configuration to allow it in AIX? I
    > have also post this question in the AIX forum.


    Impossible to say what the problem is based on this info.

    Try read output and error from the process and see if
    you get some relevant info back.

    Arne
     
    Arne Vajhøj, Sep 23, 2011
    #3
  4. SamuelXiao

    SamuelXiao Guest

    On Sep 23, 5:56 am, Daniel Pitts
    <> wrote:
    > On 9/22/11 8:09 AM, SamuelXiao wrote:
    >
    >
    >
    >
    >
    >
    >
    > > Hi All,

    >
    > > I have a Java program that needs to run a command in AIX environment.
    > > The code is as follows:

    >
    > > String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log |
    > > mailx -s 'Testing' "};
    > > Process process = Runtime.getRuntime().exec(cmds);

    >
    > > But I found that it does not work, the cmd is fine because I have
    > > tried it in AIX without using these code. It seems that AIX does not
    > > allow the process to be created?

    >
    > > Does anyone know if there is any configuration to allow it in AIX? I
    > > have also post this question in the AIX forum.

    >
    > > Any help would be highly appreciated.

    >
    > Read the javadocs for process. You need to have something reading the
    > stdout/stderr, or they may block when the buffer fills.
    >
    > Also, consider using ProcessBuilder instead.
    >
    > <http://download.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder...>


    Thanks for your reply. I cannot use ProcessBuilder because the program
    uses Java 1.4.
    The environment is as follows:
    Java: 1.4.x
    AIX 5.3
     
    SamuelXiao, Sep 23, 2011
    #4
  5. SamuelXiao

    SamuelXiao Guest

    On Sep 23, 9:20 am, Arne Vajhøj <> wrote:
    > On 9/22/2011 11:09 AM, SamuelXiao wrote:
    >
    > > I have a Java program that needs to run a command in AIX environment.
    > > The code is as follows:

    >
    > > String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log |
    > > mailx -s 'Testing' "};
    > > Process process = Runtime.getRuntime().exec(cmds);

    >
    > > But I found that it does not work, the cmd is fine because I have
    > > tried it in AIX without using these code. It seems that AIX does not
    > > allow the process to be created?

    >
    > > Does anyone know if there is any configuration to allow it in AIX? I
    > > have also post this question in the AIX forum.

    >
    > Impossible to say what the problem is based on this info.
    >
    > Try read output and error from the process and see if
    > you get some relevant info back.
    >
    > Arne


    Hi Arne,

    Actually, I used this:

    String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log |
    mailx -s 'Testing' "};
    System.out.println("Before process run");
    Process process = Runtime.getRuntime().exec(cmds);
    System.out.println("After process run");

    both message displayed, but the process really not running.

    Thanks.
     
    SamuelXiao, Sep 23, 2011
    #5
  6. SamuelXiao

    Daniel Pitts Guest

    On 9/23/11 7:31 AM, SamuelXiao wrote:
    > On Sep 23, 5:56 am, Daniel Pitts
    > <> wrote:
    >> On 9/22/11 8:09 AM, SamuelXiao wrote:
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>> Hi All,

    >>
    >>> I have a Java program that needs to run a command in AIX environment.
    >>> The code is as follows:

    >>
    >>> String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log |
    >>> mailx -s 'Testing' "};
    >>> Process process = Runtime.getRuntime().exec(cmds);

    >>
    >>> But I found that it does not work, the cmd is fine because I have
    >>> tried it in AIX without using these code. It seems that AIX does not
    >>> allow the process to be created?

    >>
    >>> Does anyone know if there is any configuration to allow it in AIX? I
    >>> have also post this question in the AIX forum.

    >>
    >>> Any help would be highly appreciated.

    >>
    >> Read the javadocs for process. You need to have something reading the
    >> stdout/stderr, or they may block when the buffer fills.
    >>
    >> Also, consider using ProcessBuilder instead.
    >>
    >> <http://download.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder...>

    >
    > Thanks for your reply. I cannot use ProcessBuilder because the program
    > uses Java 1.4.
    > The environment is as follows:
    > Java: 1.4.x
    > AIX 5.3

    My advice still applies, you need to "drain" the stdout and stderr buffer.

    It is unfortunate that you are on such an antiquated set up. Java 1.4
    was surpassed by Java 1.5 on September 30, 2004, nearly 7 years ago.
     
    Daniel Pitts, Sep 23, 2011
    #6
  7. SamuelXiao

    Arne Vajhøj Guest

    On 9/23/2011 10:35 AM, SamuelXiao wrote:
    > On Sep 23, 9:20 am, Arne Vajhøj<> wrote:
    >> On 9/22/2011 11:09 AM, SamuelXiao wrote:
    >>
    >>> I have a Java program that needs to run a command in AIX environment.
    >>> The code is as follows:

    >>
    >>> String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log |
    >>> mailx -s 'Testing' "};
    >>> Process process = Runtime.getRuntime().exec(cmds);

    >>
    >>> But I found that it does not work, the cmd is fine because I have
    >>> tried it in AIX without using these code. It seems that AIX does not
    >>> allow the process to be created?

    >>
    >>> Does anyone know if there is any configuration to allow it in AIX? I
    >>> have also post this question in the AIX forum.

    >>
    >> Impossible to say what the problem is based on this info.
    >>
    >> Try read output and error from the process and see if
    >> you get some relevant info back.

    >
    > Hi Arne,
    >
    > Actually, I used this:
    >
    > String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log |
    > mailx -s 'Testing' "};
    > System.out.println("Before process run");
    > Process process = Runtime.getRuntime().exec(cmds);
    > System.out.println("After process run");
    >
    > both message displayed, but the process really not running.


    That code is not reading output and error from the
    process.

    Try do that.

    Arne
     
    Arne Vajhøj, Sep 23, 2011
    #7
  8. Arne Vajhøj <> wrote:
    > On 9/23/2011 10:35 AM, SamuelXiao wrote:
    >> String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log |
    >> mailx -s 'Testing' "};
    >> System.out.println("Before process run");
    >> Process process = Runtime.getRuntime().exec(cmds);
    >> System.out.println("After process run");
    >> both message displayed, but the process really not running.

    > That code is not reading output and error from the process.


    What may be even more relevant than reading from channels
    that likely won't send data, anyway, is to call .waitFor()
    on the process returned by the .exec(...)-call, in order to
    ensure that "After process run" is really printed after the
    run, instead of already after merely being kicked off.

    Reading from the error channel, like Arne suggested, might
    still be a good idea - unless you really don't care about
    any failures of uuencode or mailx. Logging errors could also
    be done by ">>/tmp/debug-uuencode-and-mailx.log 2>&1" added
    to the little ksh-script.
     
    Andreas Leitgeb, Sep 24, 2011
    #8
  9. On 9/23/2011 8:14 PM, Andreas Leitgeb wrote:
    > Arne Vajhøj<> wrote:
    >> On 9/23/2011 10:35 AM, SamuelXiao wrote:
    >>> String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log |
    >>> mailx -s 'Testing' "};
    >>> System.out.println("Before process run");
    >>> Process process = Runtime.getRuntime().exec(cmds);
    >>> System.out.println("After process run");
    >>> both message displayed, but the process really not running.

    >> That code is not reading output and error from the process.

    >
    > What may be even more relevant than reading from channels
    > that likely won't send data, anyway, is to call .waitFor()
    > on the process returned by the .exec(...)-call, in order to
    > ensure that "After process run" is really printed after the
    > run, instead of already after merely being kicked off.
    >
    > Reading from the error channel, like Arne suggested, might
    > still be a good idea - unless you really don't care about
    > any failures of uuencode or mailx. Logging errors could also
    > be done by ">>/tmp/debug-uuencode-and-mailx.log 2>&1" added
    > to the little ksh-script.


    If the command fails then I would expect some errors
    in either output or error. But then I don't know those
    *nix commands, so I may be wrong.

    Arne
     
    Arne Vajhøj, Sep 24, 2011
    #9
  10. SamuelXiao

    Lars Enderin Guest

    2011-09-23 23:45, Arne Vajhøj skrev:

    > Try do that.


    Jag påminner om att "Try do" och liknande inte är korrekt engelska.
    Skriv "Try to (infinitiv)" eller "Try *ing". Alltså "Try to do that"
    eller "Try doing that".
     
    Lars Enderin, Sep 24, 2011
    #10
  11. SamuelXiao

    Roedy Green Guest

    On Fri, 23 Sep 2011 07:35:15 -0700 (PDT), SamuelXiao
    <> wrote, quoted or indirectly quoted someone
    who said :

    >
    >String[] cmds =3D{"/bin/ksh","-c","uuenco


    Start simple, say an echo command or whatever AIX uses to display a
    text message.

    Then gradually add the complexity.

    If you can't even get that to work try running an executable rather
    than a script.


    See http://mindprod.com/jgloss/exec.html
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    It should not be considered an error when the user starts something
    already started or stops something already stopped. This applies
    to browsers, services, editors... It is inexcusable to
    punish the user by requiring some elaborate sequence to atone,
    e.g. open the task editor, find and kill some processes.
     
    Roedy Green, Sep 25, 2011
    #11
  12. SamuelXiao

    Roedy Green Guest

    On Sat, 24 Sep 2011 10:59:19 +0200, Lars Enderin
    <> wrote, quoted or indirectly quoted someone
    who said :

    >Jag påminner om att "Try do" och liknande inte är korrekt engelska.
    >Skriv "Try to (infinitiv)" eller "Try *ing". Alltså "Try to do that"
    >eller "Try doing that".


    From the name, the person you are talking to might speak Chinese, but
    I doubt Swedish.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    It should not be considered an error when the user starts something
    already started or stops something already stopped. This applies
    to browsers, services, editors... It is inexcusable to
    punish the user by requiring some elaborate sequence to atone,
    e.g. open the task editor, find and kill some processes.
     
    Roedy Green, Sep 26, 2011
    #12
  13. Roedy Green <> wrote:
    > On Sat, 24 Sep 2011 10:59:19 +0200, Lars Enderin
    ><> wrote, quoted or indirectly quoted someone
    > who said :
    >> Jag påminner om att "Try do" och liknande inte är korrekt engelska.
    >> Skriv "Try to (infinitiv)" eller "Try *ing". Alltså "Try to do that"
    >> eller "Try doing that".

    > From the name, the person you are talking to might speak Chinese, but
    > I doubt Swedish.


    Lars merely gave Arne a brief English lesson :)
     
    Andreas Leitgeb, Sep 26, 2011
    #13
  14. SamuelXiao

    SamuelXiao Guest

    On Sep 23, 8:14 pm, Andreas Leitgeb <>
    wrote:
    > Arne Vajhøj <> wrote:
    > > On 9/23/2011 10:35 AM, SamuelXiao wrote:
    > >> String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log|
    > >> mailx -s 'Testing' "};
    > >> System.out.println("Before process run");
    > >> Process process = Runtime.getRuntime().exec(cmds);
    > >> System.out.println("After process run");
    > >> both message displayed, but the process really not running.

    > > That code is not reading output and error from the process.

    >
    > What may be even more relevant than reading from channels
    > that likely won't send data, anyway, is to call .waitFor()
    > on the process returned by the .exec(...)-call, in order to
    > ensure that "After process run" is really printed after the
    > run, instead of already after merely being kicked off.
    >
    > Reading from the error channel, like Arne suggested, might
    > still be a good idea - unless you really don't care about
    > any failures of uuencode or mailx.  Logging errors could also
    > be done by ">>/tmp/debug-uuencode-and-mailx.log 2>&1" added
    > to the little ksh-script.


    Hi all,

    Thanks very much, the problem has been solved. After I added
    p.waitfor() after .exec(cmds), the process run successfully. Although
    I don't know why need to add waitfor() to it.

    Thanks
     
    SamuelXiao, Sep 26, 2011
    #14
  15. SamuelXiao

    Lars Enderin Guest

    2011-09-26 11:32, Andreas Leitgeb skrev:
    > Roedy Green <> wrote:
    >> On Sat, 24 Sep 2011 10:59:19 +0200, Lars Enderin
    >> <> wrote, quoted or indirectly quoted someone
    >> who said :
    >>> Jag påminner om att "Try do" och liknande inte är korrekt engelska.
    >>> Skriv "Try to (infinitiv)" eller "Try *ing". Alltså "Try to do that"
    >>> eller "Try doing that".

    >> From the name, the person you are talking to might speak Chinese, but
    >> I doubt Swedish.

    >
    > Lars merely gave Arne a brief English lesson :)
    >

    Arne is a Dane. He understands written Swedish. I made a mistake. I
    shouldn't have posted, just sent a personal message.
     
    Lars Enderin, Sep 26, 2011
    #15
  16. SamuelXiao <> wrote:
    >> >> String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log |
    >> >> mailx -s 'Testing' "};
    >> >> System.out.println("Before process run");
    >> >> Process process = Runtime.getRuntime().exec(cmds);
    >> >> System.out.println("After process run");
    >> >> both message displayed, but the process really not running.

    >> What may be even more relevant [...] is to call .waitFor()
    >> on the process returned by the .exec(...)-call,

    >
    > Thanks very much, the problem has been solved. After I added
    > p.waitfor() after .exec(cmds), the process run successfully.
    > Although I don't know why need to add waitfor() to it.


    ..exec(...) starts the child process,
    ..waitFor() lets the parent process wait, till the child process
    has completed running.

    Normally, the email should still be sent, even without .waitFor(),
    but then it runs asynchronously to the parent process, which again
    means, that the second println happens before the child process has
    even had a chance to do anything. .waitFor() is merely synchronization.
     
    Andreas Leitgeb, Sep 26, 2011
    #16
  17. SamuelXiao

    Arne Vajhøj Guest

    On 9/26/2011 5:27 AM, Roedy Green wrote:
    > On Sat, 24 Sep 2011 10:59:19 +0200, Lars Enderin
    > <> wrote, quoted or indirectly quoted someone
    > who said :
    >
    >> Jag påminner om att "Try do" och liknande inte är korrekt engelska.
    >> Skriv "Try to (infinitiv)" eller "Try *ing". Alltså "Try to do that"
    >> eller "Try doing that".

    >
    > From the name, the person you are talking to might speak Chinese, but
    > I doubt Swedish.


    Amazing what one can find using this modern thing called
    the internet:
    http://en.wikipedia.org/wiki/.dk

    Arne
     
    Arne Vajhøj, Sep 27, 2011
    #17
    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. Jakir
    Replies:
    4
    Views:
    3,223
    Jakir
    Sep 1, 2004
  2. Hal Vaughan
    Replies:
    11
    Views:
    1,119
    Gordon Beaton
    May 22, 2006
  3. Replies:
    4
    Views:
    24,075
    vivek_kothari
    Jan 12, 2010
  4. moongeegee
    Replies:
    7
    Views:
    5,466
    Arne Vajhøj
    Oct 5, 2008
  5. Replies:
    12
    Views:
    4,987
    Roedy Green
    Apr 19, 2009
Loading...

Share This Page