Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue reading command-line-args in script
    primarykey
    data
    text
    <p>I'm attempting to write a library to do some domain-specific stuff. I'd like to add some scripts to this library that can be run straight from the commandline.</p> <p>Directory layout:</p> <pre><code>+- project.clj +- src/ | +- my-lib.clj | +- my-lib/ | +- my-sub-1.clj +- scripts/ +- run-command.sh </code></pre> <p>The src/my-lib.clj file loads the my-lib/my-sub-1.clj file:</p> <pre><code>(ns my-lib (:use [my-lib.my-sub-1]) ) </code></pre> <p>The src/my-lib/my-sub-1.clj file contains the functions I want to make available. One of these functions is called "convert" and takes two arguments: an input filename and an output filename; it converts the fileformat. To use it:</p> <pre><code>(convert "input-file.txt" "output-file.txt") </code></pre> <p>The (do-something-interesting) and (convert) functions in src/my-lib/my-sub-1.clj look like this:</p> <pre><code>(defn do-something-interesting [input-file output-file] (magic-happens-here input-file output-file)) (defn convert [args] (let [infile (first args) outfile (second args)] (do-something-interesting infile outfile))) </code></pre> <p>My goal at the moment: to create a script "run-command.sh" in the "scripts" directory that takes two arguments: the input filename and output filename. It should be possible to run the script with:</p> <pre><code>./run-command.sh input-file.txt output-file.txt </code></pre> <p>I do have run-command.sh working, as long as I hard-code the filenames in that script by using the (do-something-interesting) function instead of (convert). I haven't been able yet to read from the argument list...</p> <p>The run-command.sh script that works:</p> <pre><code>#!/bin/sh java -cp "../lib/*":"../src":$CLASSPATH clojure.main -e " (use '[my-lib my-sub-1]) (do-something-interesting "path-to-input-file" "path-to-output-file") " </code></pre> <p>... but what doesn't work:</p> <pre><code>#!/bin/sh java -cp "../lib/*":"../src":$CLASSPATH clojure.main -e " (use '[my-lib my-sub-1]) (convert *command-line-args*) " </code></pre> <p>The error I get is:</p> <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: No implementation of method: :reader of protocol: #'clojure.contrib.io/Streams found for class: nil (NO_SOURCE_FILE:0) at clojure.lang.Compiler.eval(Compiler.java:5435) at clojure.lang.Compiler.eval(Compiler.java:5386) at clojure.core$eval.invoke(core.clj:2382) at clojure.main$eval_opt.invoke(main.clj:235) at clojure.main$initialize.invoke(main.clj:254) at clojure.main$null_opt.invoke(main.clj:279) at clojure.main$main.doInvoke(main.clj:354) at clojure.lang.RestFn.invoke(RestFn.java:422) at clojure.lang.Var.invoke(Var.java:369) at clojure.lang.AFn.applyToHelper(AFn.java:165) at clojure.lang.Var.applyTo(Var.java:482) at clojure.main.main(main.java:37) Caused by: java.lang.IllegalArgumentException: No implementation of method: :reader of protocol: #'clojure.contrib.io/Streams found for class: nil at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:471) at clojure.contrib.io$eval32$fn__33$G__23__38.invoke(io.clj:118) at bioclojure.vcf$header.invoke(vcf.clj:22) at bioclojure.vcf$column_header.invoke(vcf.clj:55) at bioclojure.vcf$column_names.invoke(vcf.clj:61) at bioclojure.vcf$vcf2tsv.invoke(vcf.clj:169) at bioclojure.vcf$convert.invoke(vcf.clj:185) at user$eval474.invoke(NO_SOURCE_FILE:3) at clojure.lang.Compiler.eval(Compiler.java:5419) ... 11 more </code></pre> <p>I've tried "use"ing clojure.contrib.io within the script file run-command.sh itself, and within the top library file my-lib.clj, but no luck so far...</p> <p>If anyone could help me out that'd be great.</p> <p>jan.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload