Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure 如何将shell脚本打包到leiningen项目中_Clojure_Leiningen - Fatal编程技术网

Clojure 如何将shell脚本打包到leiningen项目中

Clojure 如何将shell脚本打包到leiningen项目中,clojure,leiningen,Clojure,Leiningen,我有一个保存在scripts/shell/record\u video.sh中的shell脚本,我需要调用其中一个项目 其在代码中的使用示例: (defn save-mp4 [cam filename duration] (sh "scripts/shell/record_video.sh" (:i_url cam) filename (str duration))) 如果我上传到clojars,我如何才能jar项目,从而包含shell脚本 跟进 谢谢@Ankur。(sh“bash”:在

我有一个保存在
scripts/shell/record\u video.sh
中的shell脚本,我需要调用其中一个项目

其在代码中的使用示例:

(defn save-mp4 [cam filename duration]
  (sh "scripts/shell/record_video.sh" (:i_url cam) filename (str duration)))
如果我上传到clojars,我如何才能jar项目,从而包含shell脚本


跟进 谢谢@Ankur。
(sh“bash”:在bash命令字符串中)
非常有用。首先,我需要
.sh
文件的唯一原因是,当标准输出包含一些大的内容(如视频)时,我不太明白如何进行重定向

文件
scripts/shell/record\u video.sh
包含:

SRC=rtsp://$1:554/axis-media/media.amp?resolution=1920x1080
DST=$2
LEN=$3
openRTSP -4 -d $LEN -w 1440 -h 1080 -f 25 -u root pass $SRC > $DST 2> /dev/null
我不知道如何翻译重定向(
)而不使程序内存消耗巨大。
(sh“bash”:在bash命令字符串中)
命令允许在不使用shell脚本的情况下编写我的函数:

(defn save-mp4 [cam filename duration]
  (let [src (format "rtsp://%s:554/axis-media/media.amp?resolution=1920x1080" (:i_url cam))
        cmd (format "openRTSP -4 -d %d -w 1440 -h 1080 -f 25 -u root pass %s > %s 2> /dev/null"
                    duration src filename)]
    (sh "bash" :in cmd)))

你实际上有两个问题。首先,如何将文件放入jar文件。第二,如何从jar文件中访问该文件

第一个非常简单:将文件包含在resources目录中。该目录中的所有文件都包含在jar文件中

第二个更难,因为
sh
将在磁盘上查找脚本,而不是嵌套在jar文件中。您可能需要使用class loader.getresource提取文件,然后将其写入磁盘以执行

关于如何从jar中读取资源,有一个简单的方法,最简单的是
(clojure.java.io/resource“myscript.js”)
两个步骤:

  • 将shell脚本打包为资源
  • 使用java资源API读取shell脚本文件并使用
    (sh“bash”:在文件str中)

其中file str是使用资源API读取的shell脚本内容。

:in
字符串传递给正在启动的进程的标准输入。。因此,这基本上是启动bash,然后将脚本代码写入bash stdin,因此bash将执行该脚本。。像你这样的人
echo'echo hello'| bash