Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird output from echo called from a java application

Status
Not open for further replies.

AnthonyGeorge

Technical User
Jun 3, 2004
46
GB
The aim of this application is to translate a en Var such as $PATH into its path such as /usr/bin.

Before I give the code listing and environment can anyone think of any UNIX reason that given echo $PATH, the application will output back $PATH and not the path /usr/bin.

My java code works as a standalone application, it is when it is called from a Oracle Store procedure that it outputs back what was inputed in.

As a stand alone if I input $TONY it will throw an exception as there is no envar mapped to $TONY.

If I input TONY then it will output TONY, this is the same resault as from the application called the Oracle database.

Is there a problem with unix commands and Oracle.

Code listing below:

import java.io.*;
import java.util.*;

class translate
{
public static String translatePath(String envar)
{
Runtime rt = Runtime.getRuntime();
Process p = null;
String echoOutput = null;

int len = 0;

try
{
System.out.println("Calling echo "+envar);

p = rt.exec(new String[]{"/bin/echo",envar});

InputStreamReader isr = new InputStreamReader(p.getInputStream());
BufferedReader br = new BufferedReader(isr);
echoOutput = br.readLine();

br.close();
isr.close();
return echoOutput;
}
catch(Exception e)
{
System.out.println("Exception "+e);
return "ProcessProblem";
}

//path = "/rims/live/log";

}
}
Thanks for any advice or help

Tony
 
In unix, the $ expansion is done by a shell.
When you launch a program by exec family system call, the environment is passed as an array and it's the program responsability to retrieve the value of an environment variable.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top