Shell output vs Process streams

M

Marcus Leon

I'm trying to call a shell script from Java and read the script output.
Right now I get different text when I run the script from the command
line vs. when I run it from Java using the Process class. Does anyone
know why? Thanks.

Output From Command Line:
UID: readonly variable
ambiguous redirect
continue: only meaningful in a `for', `while', or `until' loop

Process.getErrorStream() Text:
/export/home/weblogic/fullexport.sh:
ORACLE_HOME=/u01/app/oracle/product/9.2.0: is not an identifier

Process.getInputStream() Text:
<blank>

My Java Program:
Process proc = Runtime.getRuntime().exec(args[0]) ;

BufferedReader br1 = new BufferedReader(new
InputStreamReader(proc.getErrorStream()));
while ((str = br1.readLine()) != null) {
error += (str + "\n");
}

BufferedReader br2 = new BufferedReader(new
InputStreamReader(proc.getInputStream()));
while ((str = br2.readLine()) != null) {
input += (str + "\n");
}
 
G

Gordon Beaton

I'm trying to call a shell script from Java and read the script
output. Right now I get different text when I run the script from
the command line vs. when I run it from Java using the Process
class. Does anyone know why? Thanks.

Aside from the apparent errors in the script based on the output
you've provided, I suspect the environment seen by the script is
different when run from Java than when run from the command line.

Not really a java issue, but perhaps you should read the manpage for
your shell, and look for things explaining the differences between
interactive and non-interactive shells, and login and non-login
shells.

/gordon
 

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

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top