Unix 'expr'-- trying runtime.exec

My shop relies heavily on unix environment variables. I'm trying to mimic the functionality of the 'expr' command in Java so my program will easily fit in. Currently I'm trying to do this using runtime.exec, but I am by no means attached to that method.

I would like to be able to take an expression like '$HOME/cat/dog.java' and turn it into 'theuser/cat/dog/java' .

-I'm looking for a solution compatible with 1.3, if possible

-I've already read "When Runtime.exec Won't", and lots of other articles.

The below code doesn't work since it doesn't seem to be able to view the shell variables. R is a global Runtime.getRuntime():

String expr(String u)throws Exception//Filter a string as a *nix expr

{

Process p = R.exec("expr "+u);

InputStream in = p.getInputStream();

String s="";

int c;

while( (c=in.read()) != -1)

s+=(char)c;

in.close();

p.waitFor();

if(s.length()>0) s=s.substring(0,s.length()-1);//Chop expr's \n

return s;

}

Any help is appreciated. Thank you very much.

[1481 byte] By [shortcodea] at [2007-11-26 17:50:57]
# 1
Oops, I thought expr was the command that does this, but I guess it isn't. To clarify, I'd like to be able to evaluate the expression $HOME/cat as the shell would, to /theuser/cat.
shortcodea at 2007-7-9 5:03:27 > top of Java-index,Java Essentials,Java Programming...
# 2

The shell expands environment variables so you need to run your command in a shell. For example

String[] command =

{

"sh",

"-c",

"ls $HOME",

}

Process p = R.exec(command);

sabre150a at 2007-7-9 5:03:27 > top of Java-index,Java Essentials,Java Programming...
# 3
Somewhat surprisingly, your code worked. I had tried a number of variations on the same idea before with no success. I guess it takes a knowledgeable hand. Thanks for your expertise!
shortcodea at 2007-7-9 5:03:27 > top of Java-index,Java Essentials,Java Programming...