osa1
osa1

Reputation: 7078

How to run a Clojure app with command line parameters

To run Clojure files from command line, I'm using a zhs alias I added to my .zshrc:

alias 'clojure=java -cp /home/sinan/cclojure/lib/clojure-1.2.1.jar:/home/sinan/cclojure/lib/clojure-contrib-1.2.0.jar clojure.main -i '

With this, I can run my Clojure app like this:

clojure test3.clj

But it doesn't work when I want to send command line parameters.

➜  src  clojure test3.clj arg1 arg2
Exception in thread "main" java.io.FileNotFoundException: arg1 (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:120)
        at java.io.FileInputStream.<init>(FileInputStream.java:79)
        at clojure.lang.Compiler.loadFile(Compiler.java:5817)
        at clojure.main$load_script.invoke(main.clj:221)
        at clojure.main$script_opt.invoke(main.clj:273)
        at clojure.main$main.doInvoke(main.clj:354)
        at clojure.lang.RestFn.invoke(RestFn.java:457)
        at clojure.lang.Var.invoke(Var.java:377)
        at clojure.lang.AFn.applyToHelper(AFn.java:172)
        at clojure.lang.Var.applyTo(Var.java:482)
        at clojure.main.main(main.java:37)

What am I doing wrong? Is my way of running Clojure apps wrong?

Thanks.

Upvotes: 0

Views: 1170

Answers (1)

Alex Ott
Alex Ott

Reputation: 87109

you just need to specify name of script, without -i key after clojure.main. In your case, clojure.main thinks, that test.clj is program to eval before (and it do it), while arg1 is script to execute

See description of option for clojure.main/main function

Upvotes: 3

Related Questions