This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-06
Channels
- # aleph (2)
- # arachne (4)
- # aws (3)
- # beginners (196)
- # cider (131)
- # cljs-dev (208)
- # clojure (193)
- # clojure-boston (1)
- # clojure-dev (26)
- # clojure-greece (4)
- # clojure-italy (26)
- # clojure-losangeles (1)
- # clojure-russia (11)
- # clojure-spec (40)
- # clojure-uk (78)
- # clojurescript (168)
- # cursive (25)
- # datascript (1)
- # datomic (31)
- # docker (8)
- # docs (1)
- # emacs (20)
- # fulcro (62)
- # hoplon (3)
- # jobs (1)
- # leiningen (3)
- # luminus (1)
- # nrepl (25)
- # off-topic (10)
- # other-languages (3)
- # parinfer (11)
- # planck (37)
- # portkey (54)
- # protorepl (11)
- # re-frame (2)
- # reagent (19)
- # remote-jobs (1)
- # ring (2)
- # rum (8)
- # shadow-cljs (23)
- # spacemacs (4)
- # uncomplicate (6)
- # unrepl (77)
- # vim (56)
- # yada (2)
How can I pass environment variables to shell process? I want to execute this command from planck AWS_PROFILE=foo aws s3 ls
. But when I try this way (planck.shell/sh "aws" "s3" "ls" :env {"AWS_PROFILE" "foo"})
I got an error "launch path not accessible"
. Thanks!
cljs.user=> (require 'planck.shell)
nil
cljs.user=> (planck.shell/sh "aws" "s3" "ls")
{:exit 255, :out "", :err "Unable to locate credentials. You can configure credentials by running \"aws configure\".\n"}
cljs.user=>
@tothda As a sanity check, you could fire up a Clojure REPL and try the same command, but instead using [clojure.java.shell :as shell]
to see if it reveals more.
If Planck's code sees exit codes of 126 and 127 it throws that exception. I can't recall exactly why, but the goal is to behave like clojure.java.shell
.
@tothda Well, one cool thing you can do, since Planck is self-hosted, is dynamically re-define the behavior.
If you do (in-ns 'planck.shell)
in a Planck REPL you can then
(defn- sh-internal
[& args]
(let [{:keys [cmd opts cb]} (s/conform ::sh-async-args args)]
(when (nil? cmd)
(throw (s/explain ::sh-async-args args)))
(when-not (s/valid? (s/nilable ::string-string-map?) *sh-env*)
(throw (js/Error. (s/explain-str ::string-string-map? *sh-env*))))
(let [{:keys [in in-enc out-enc env dir]}
(merge {:out-enc nil :in-enc nil :dir (and *sh-dir* [:sh-dir *sh-dir*]) :env *sh-env*}
(into {} (map (comp (juxt :key :val) second) opts)))
dir (and dir (:path (as-file (second dir))))
async? (not= cb nil-func)
translated (translate-result (js/PLANCK_SHELL_SH (clj->js cmd) in in-enc out-enc
(clj->js (seq env)) dir (if async? (assoc-cb cb))))
{:keys [exit err]} translated]
(if async? nil translated))))
This would get rid of the code that looks at the exit values and it will let you see the true :exit
and :err
I wonder if aws
is itself a script that has an interpreter that isn't found with the way Planck launches it.
aws
was installed with brew
and the shebang line is #!/usr/local/Cellar/awscli/1.11.170/libexec/bin/python
127
means it can't find the command http://tldp.org/LDP/abs/html/exitcodes.html
@tothda Still, digging, but a (unsavory) workaround appears to be to set the environment prior to running Planck, as in
AWS_PROFILE=foo planck
@tothda Discovered that if you set any env, Planck blows away the needed PATH
environment variable. I'm looking into the Java source code to see what it actually does in that case that allows it to succeed. So two more workarounds result from this discovery:
1. Use "/usr/local/bin/aws"
as the first parameter to sh
2. If you specify an env map, include a "PATH"
key, with "/usr/local/bin"
and whatever else might be needed.
I'm going to fix the underlying Planck issue to make it behave like clojure.java.shell
@tothda Was able to fix it. That was a good catch. In summary, Planck needs to ensure that the environment passed is for the child process. It was messing with the parent process, and thus breaking the ability to even find things on the PATH
.