clojure conch的shell api没有显示像java这样的外部命令的结果

时间:2014-09-18 11:32:10

标签: shell clojure

我想在我的项目中使用clojure脚本进行开发任务,比如使用clojure脚本等运行项目。

我使用lein-off lein plugin和clojure conch库进行shell api,脚本如下(dubofsky.clj

(defdeps                                                                                                                                                                         
    [[org.clojure/clojure "1.6.0"]                                                                                                                       
     [me.raynes/conch "0.8.0"]])                                                                    

(ns deploy                                                                                          
    (use [clojure.java.shell :only  [sh]])                                                          
    (:require [me.raynes.conch.low-level :as shell]))

  (sh "sh" "-c" "echo hello > /dev/null")
  (print (shell/stream-to-string (shell/proc "echo" "....................................") :out))
  (print (shell/stream-to-string (shell/proc "echo" "Project starting...") :out))
  (print (shell/stream-to-string (shell/proc "grails" "run-app") :out))
  (print (shell/stream-to-string (shell/proc "bash" "--version") :out))

但是在lein oneoff dubofsky.clj上,似乎无法打印javagrails等外部命令的输出。

以上脚本的结果是

$ lein oneoff --exec devops.clj 
....................................
Project starting...
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

This is exactly similar problem to mine

1 个答案:

答案 0 :(得分:1)

Shell进程有两个已定义的输出流stdout和stderr。你只是捕获stdout。 java -version命令不会打印到stdout,它只打印到stderr。

user> (print (shell/stream-to-string (shell/proc "java" "-version") :out))
nil
user> (print (shell/stream-to-string (shell/proc "java" "-version") :err))
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
nil