Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Java Runtime getRuntime().exec not work in AIX

486 views
Skip to first unread message

Samuel Xiao

unread,
Sep 22, 2011, 11:09:09 AM9/22/11
to
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' a...@example.com "};
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 Java forum.

Any help would be highly appreciated.

Gerard H. Pille

unread,
Sep 22, 2011, 1:55:08 PM9/22/11
to
Java is no good to start other jobs, poorly equiped to do so.

But there are problems with your command too. Are uuencode and mailx on PATH? Is HOME defined
for mailx? Don't you need to escape the @ ? How will you detect what it is that does not
work? With exec you can pass an environment, but you don't.

What gives:

String[] cmds ={"/bin/ksh","-c","printenv > /tmp/printenv.log 2>&1"};
Process process = Runtime.getRuntime().exec(cmds);

Samuel Xiao

unread,
Sep 23, 2011, 10:25:12 AM9/23/11
to
Thanks for your reply.

Let me explain more, the cmds is ok because I directly type it on AIX
and it really sent an email with an attachment.
I detect it by :

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

Both text are displayed so I am quite sure it is the problem of
Process process = Runtime.getRuntime().exec(cmds);

Gerard H. Pille

unread,
Sep 25, 2011, 7:51:08 AM9/25/11
to
Samuel Xiao wrote:

> Let me explain more, the cmds is ok because I directly type it on AIX

Let me explain to you: a commend entered in a korn shell, is not the same as a command executed
by Runtime.getRuntime().exec.

> and it really sent an email with an attachment.

Which one? From the command line or from Java?

Now, try the printenv I gave you.

Samuel Xiao

unread,
Sep 26, 2011, 11:29:12 AM9/26/11
to
Hi,

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

Gerard H. Pille

unread,
Sep 26, 2011, 1:55:01 PM9/26/11
to
When a parent proces terminates, all children are automatically terminated.

The command you spawned never got a chance to run.
0 new messages