Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Java Runtime getRuntime().exec not work in AIX (http://www.velocityreviews.com/forums/t754348-java-runtime-getruntime-exec-not-work-in-aix.html)

SamuelXiao 09-22-2011 03:09 PM

Java Runtime getRuntime().exec not work in AIX
 
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' abc@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 AIX forum.

Any help would be highly appreciated.

Daniel Pitts 09-22-2011 09:56 PM

Re: Java Runtime getRuntime().exec not work in AIX
 
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' abc@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 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>

Arne Vajh°j 09-23-2011 01:20 AM

Re: Java Runtime getRuntime().exec not work in AIX
 
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' abc@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 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



SamuelXiao 09-23-2011 02:31 PM

Re: Java Runtime getRuntime().exec not work in AIX
 
On Sep 23, 5:56*am, Daniel Pitts
<newsgroup.nos...@virtualinfinity.net> 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' 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 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 09-23-2011 02:35 PM

Re: Java Runtime getRuntime().exec not work in AIX
 
On Sep 23, 9:20*am, Arne Vajh°j <a...@vajhoej.dk> 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' 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 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' a...@example.com "};
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.

Daniel Pitts 09-23-2011 05:20 PM

Re: Java Runtime getRuntime().exec not work in AIX
 
On 9/23/11 7:31 AM, SamuelXiao wrote:
> On Sep 23, 5:56 am, Daniel Pitts
> <newsgroup.nos...@virtualinfinity.net> 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' 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 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.

Arne Vajh°j 09-23-2011 09:45 PM

Re: Java Runtime getRuntime().exec not work in AIX
 
On 9/23/2011 10:35 AM, SamuelXiao wrote:
> On Sep 23, 9:20 am, Arne Vajh°j<a...@vajhoej.dk> 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' 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 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' a...@example.com "};
> 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



Andreas Leitgeb 09-24-2011 12:14 AM

Re: Java Runtime getRuntime().exec not work in AIX
 
Arne Vajh├Şj <arne@vajhoej.dk> wrote:
> On 9/23/2011 10:35 AM, SamuelXiao wrote:
>> 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 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.


Arne Vajh├Şj 09-24-2011 12:41 AM

Re: Java Runtime getRuntime().exec not work in AIX
 
On 9/23/2011 8:14 PM, Andreas Leitgeb wrote:
> Arne Vajh├Şj<arne@vajhoej.dk> wrote:
>> On 9/23/2011 10:35 AM, SamuelXiao wrote:
>>> 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 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



Lars Enderin 09-24-2011 08:59 AM

Re: Java Runtime getRuntime().exec not work in AIX
 
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".





All times are GMT. The time now is 10:43 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.