Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Runtime.getRuntime().exec() ??

Reply
Thread Tools

Runtime.getRuntime().exec() ??

 
 
Andrew Regan
Guest
Posts: n/a
 
      06-28-2004
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


 
Reply With Quote
 
 
 
 
WagnerR
Guest
Posts: n/a
 
      06-28-2004
Don't know if this will cover your problem or not, but there was an excellent
article covering usage of exec() at

http://www.javaworld.com/javaworld/j...229-traps.html

hth,
Ron Wagner
 
Reply With Quote
 
 
 
 
Steve Horsley
Guest
Posts: n/a
 
      06-28-2004
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
 
Reply With Quote
 
Yu SONG
Guest
Posts: n/a
 
      06-29-2004
"Andrew Regan" <(E-Mail Removed)>
> 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/
__________________________________________________ _____


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments