unix - Executing cd and pwd in java program -


i have java program executes cd unix command follows:

process p =  runtime.getruntime().exec("/bin/sh -c cd test_dir"); 

now when try pwd i'm getting dir java program resides , not dir changed (should /root/test_dir)

process pr = runtime.getruntime().exec("pwd"); 

any suggestions on this?

a child process can't change working directory of parent. use processbuilder.directory(file) set working directory child process. like,

processbuilder pb = new processbuilder("pwd"); pb.directory(new file("test_dir")); pb.inheritio(); pb.start(); 

Comments