简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM