I am trying to create a Unix shell in Java. Everything works great expect for the "cd" change directory command. Anytime I try to change directories, it remains in the same directory.
I took a look at this with no luck.
Here is a snippet of the code that I am using.
try
{
Process p = null;
File directory = new File("/Users/myName");
if(inputList.get(0).equals("cd")
{
System.setProperty("user.dir", "Users/myName");
System.out.println(System.getProperty("user.dir"));
ProcessBuilder pb = new ProcessBuilder("cd");
pb.directory(directory);
System.out.println(pb.directory);
p = pb.start();
}
}
Note that when printing the getProperty command returns to me the correct directory address. Also note that when printing pb.directory(), it also prints out the correct directory address. However when executing the "pwd" command next, it shows that I am in the directory of my project.