views:

53

answers:

1
ProcessBuilder pb = new ProcessBuilder("pwd");
pb.directory(new File("/server1/work/uz/rt/adapt/0/"));
Process s = pb.start();

I expected the output to be /server1/work/uz/rt/adapt/0/, but instead it's:

/work/uz/rt/adapt/0/

/work/uz/rt/adapt/0/ and /server1/work/uz/rt/adapt/0/ are equivalent (mounted at the same place,/work/.. is correct path and /server1/work/.. is the mounted one ), but I need to work under /server1/work/uz/rt/adapt/0/ because some other servers only work through that path.

How can I make /server1/work/uz/rt/adapt/0/ the current path?

IN OTHER WORDS

why public ProcessBuilder directory(File directory) converts directory into canonical File. How can I use absolute File Path??

I also tried the hack soln'

        pb.directory(new File("/asr1/work/oguz/rt/adaptMLLR2/0/"){
             public File getCanonicalFile(){
                 return this.getAbsoluteFile();
             }
             public String getCanonicalPath() {
                 return this.getAbsolutePath();
             }

        });

which didnt work as well.

I resolved my problem by adding cd /server1/.. line in to the bash script.. and deleted pd.directory(..) line. BUT this problem (why I cant use pd.directory(..) with absolutePath ) is not answered yet...???

A: 

Using a shell's cd utility seems an appropriate solution. An alternative would be to set the PWD environment variable to the pathname with symlinks, but this is ugly unless you get ProcessBuilder to do it for you automatically.

Note that shells ignore PWD if it is not an absolute pathname for the current directory, asking the system for a absolute pathname without symlinks instead.

jilles