views:

77

answers:

1

What I'm looking for is this kind of command line interaction at the Windows command line:

C:\temp1>clj some_script.clj
C:\temp2>

Where some_script.clj contains something like:

(cd "c:\\temp2")

So the question is - how do I implement the function cd? Have experimented with clojure.java.shell, but it does not look like the lib I need. This might be a simple question, the problem might be that I'm not fluent in Java?!

+4  A: 

You can't do this in Java, so you can't do it in Clojure. See http://stackoverflow.com/questions/840190/changing-the-current-working-directory-in-java

Stefan Tilkov
That is really hard to believe. There's always a way, isn't there? Hmm, maybe I'll end up with a polyglot solution, shelling out from clojure to ruby for the directory change... :)
Torbjørn
It's also hard to believe the classpath is fixed at runtime, but it's true. Hotspot is a bizarre mix of amazing engineering prowess and boneheaded mistakes.
technomancy
Working directories are a very platform-specific feature. I actually think it's a very good design decision for a platform-independent language such as Java to avoid being tied to platform specific semantics, especially when there are plenty of other ways to achieve the same result. I'm sure if you are really determined, you could solve the problem in a platform-specific way using JNI.
mikera