Hi all, I managed to make this work by first making a clj script as instructed here: http://en.wikibooks.org/wiki/Clojure_Programming/Getting_Started (thanks, great stuff!)
But there is still one small thing: Is there an elegant way to "unwrap" the passed command line arguments? And is there any module in Clojure to parse command line arguments like Ruby and Pythons "optparse"? My tiny script: ------------------ #! /usr/bin/env clj (defn somefunc [& args] (println "somefunc!" args)) (defn main [& args] (somefunc args)) (when *command-line-args* (main *command-line-args*)) --------------------- When I run it from the command line I get: $ ./test.clj this is the command line args somefunc! (((./test.clj this is the command line args))) $ Best, Grunde On 4 Jan, 14:58, "Mark Volkmann" <[email protected]> wrote: > On Sun, Jan 4, 2009 at 3:57 AM, Timothy Pratley > > > > <[email protected]> wrote: > > >> I suspect that *command-line-arguments* would have "myapp.clj" as the > >> 0th element in the > >> clj myapp.clj > >> Can't test right now though sorry. > > > I tested this and it does work for me. If it does not work for you is > > most likely in your clj script or bat file. I noticed on the wiki the > > incorrect advice was given: > > java -cp %CLOJURE_JAR%;%CONTRIB_JAR% clojure.lang.Script %1 > > > I've updated the wiki with the correct usage: > > java -cp %CLOJURE_JAR%;%CONTRIB_JAR% clojure.lang.Script %1 -- %* > > > Check your script for the -- between script name and arglist. Note > > that %* includes %1. > > > script-test.clj: > > (if *command-line-args* > > (println "SCRIPT") > > (println "REPL")) > > > C:\java>clj script-test.clj > > SCRIPT > > > C:\java>clj > > Clojure > > user=> (load-file "script-test.clj") > > REPL > > nil > > Thanks! I've got it working this way now. My script defines a "main" > function. At the bottom of the script I do this: > > ; Only run the application automatically if run as a script, > ; not if loaded in a REPL with load-file. > (if *command-line-args* (main)) > > -- > R. Mark Volkmann > Object Computing, Inc. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---
