I am creating my own Shell in JAVA. Everything is going fine except changing directories. Right now, I can enter DIR and it will list my current directory. Then I issue the System.setProperty("user.dir", "C:\\Program Files"); I then type DIR again and it still show the same directory I was in before. But the user.dir has been changed. Does anyone know of a way to change directories using the exec() commands?? Apreantly, I need to change the Current Working Directory that Java uses? ------------------ Happy Coding, Gregg Bolinger [This message has been edited by Gregg Bolinger (edited December 19, 2001).]
Ok, this is beginning to get irritating. Can anyone PLEASE help me out here. Any ideas? Thanks
------------------ Happy Coding, Gregg Bolinger
Marilyn de Queiroz
Joined: Jul 22, 2000
I don't know the answer to your question. Sorry you are irritated.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Joined: Sep 29, 2000
So let me make sure that I understand what you are trying to do. You have a java program, and you are using it to create a "view" into what is going on at the operating system level, in this case windows. Is that close? What you described is that you changed some java properties, when in fact you want to do an operating system command like Process p = Runtime.getRuntime().exec("cmd start cd c:\\someOtherDir"); Of course this is going to change the directory that Process p is pointing to, which could be a different process than you are sitting in, so be carefull (translated = Cindy is not sure how to insure this based on what you have described so far). I would love to see how you get this to work, if you are willing to share your results.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Cindy, you are absolutly right in the process to do the directory change. Here is what I have set up.... I have a JFrame with 2 JTextAreas and 1 JTextField. In the Field is where I type my "DOS" commands. The First Text Area keeps track of what I did. The second displays the results. The problem I am running into, is when I change the directory, either as you specified or by System.setProperty("user.dir", "C:\\JAva"), it get's changed, FOR THAT PROCESS. But then if I type DIR then it still displays the working JAVA directory. Basically, where all my class files for the program reside. I think the problem is that it run a NEW process everytime I type a command. I need to find a way to keep the same process open for and entire session. Or as long as the window is open. I tried CMD /k, and the process keeps running, but hangs the App, and does not display my results from the commands. I have thought of a workaround, but looking for a better way. Thanks for any help. ------------------ Happy Coding, Gregg Bolinger
Joined: Jan 09, 2001
Hi Gregg, I'm still missing the point of actually doing the DOS command. You can actually fake it by just having a File point to the the location where the user thinks he should be. For example: File currentDirectory = new File( "C:\" ); DIR command entered --> currentDirectory.list(); user changes to C:\temp: currentDirectory = new File( "C:\TEMP" ); DIR command entered --> currentDirectory.list(); All this without ever having run any DOS command or changed the JVM working directory ... Regards, Manfred.
I don't necesarily want to reinvent the wheel. I want to take the current shell, and extend it through java. Also would like the shell screen to look better/different. That is why I interface it with my text areas. I have thought about doing it that way. However, I don't want to have to check for current dos commands such as DIR. I think for the time being, I will use runtime.exec to execute shell scripts and batch files that I can create. That would basically accomplish the same tasks that I wanted to extend through my own shell. But I am still researching and working on the Java Shell. They exists. Other people have made them. I found some on the net. However, I am horrible at looking through other peoples source code trying to find what I need. So it wasn't much help for me to look at it. Thanks for any help.