Java Runtime getRuntime().exec not work in AIX

S

SamuelXiao

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' (e-mail address removed) "};
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.
 
D

Daniel Pitts

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' (e-mail address removed) "};
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>
 
A

Arne Vajhøj

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' (e-mail address removed) "};
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
 
S

SamuelXiao

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' (e-mail address removed) "};
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
 
S

SamuelXiao

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' (e-mail address removed) "};
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' (e-mail address removed) "};
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.
 
D

Daniel Pitts

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' (e-mail address removed) "};
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.
 
A

Arne Vajhøj

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' (e-mail address removed) "};
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' (e-mail address removed) "};
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
 
A

Andreas Leitgeb

Arne Vajhøj said:
String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log |
mailx -s 'Testing' (e-mail address removed) "};
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.
 
A

Arne Vajhøj

Arne Vajhøj said:
String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log |
mailx -s 'Testing' (e-mail address removed) "};
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
 
L

Lars Enderin

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".
 
R

Roedy Green

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.
 
R

Roedy Green

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.
 
S

SamuelXiao

Arne Vajhøj said:
String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log|
mailx -s 'Testing' (e-mail address removed) "};
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
 
L

Lars Enderin

2011-09-26 11:32, Andreas Leitgeb skrev:
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.
 
A

Andreas Leitgeb

SamuelXiao said:
String[] cmds ={"/bin/ksh","-c","uuencode /log/test.log attached.log |
mailx -s 'Testing' (e-mail address removed) "};
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top