Hi folks, I'm almost there.
My small script: ------ #! /usr/bin/env clj (defn somefunc [& args] (println "somefunc!" args)) (defn main [& args] (somefunc args)) ; Only run the application automatically if run as a script, ; not if loaded in a REPL with load-file. (when *command-line-args* (main *command-line-args*)) ------- When I run from the command line I get: $ ./test.clj parameters here somefunc! (((./test.clj parameters here))) $ Now, it these some elegant way to parse and use the passed command line arguments in my program? Is there any lib like Ruby/Pythons optparse to assist parsing of command line arguments? Best, Grunde On 4 Jan, 14:58, "Mark Volkmann" <r.mark.volkm...@gmail.com> wrote: > On Sun, Jan 4, 2009 at 3:57 AM, Timothy Pratley > > > > <timothyprat...@gmail.com> 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 clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---