pesterhazy / bash2bb

44 stars 1 forks source link

Redirection of both stdout and stderr #3

Closed dundalek closed 1 year ago

dundalek commented 1 year ago

Given:

echo a | tee /dev/stderr >& /dev/null

Expected: Should be translated as a script that prints nothing.

Actual: Fails with Don't know how to translate redirect

Stacktrace ``` {"Op" 59, "Word" {"Parts" [{"Type" "Lit", "Value" "/dev/null"}]}} ----- Error -------------------------------------------------------------------- Type: java.lang.Exception Message: Don't know how to translate redirect Location: /home/me/.gitlibs/libs/io.github.pesterhazy/bash2bb/57c4f925273e2146b7ba8c392e3268775cef0616/src/bash2bb/core.clj:142:40 ----- Context ------------------------------------------------------------------ 138: (assoc opts :err 'System/out) 139: :else 140: (do 141: (pp redir) 142: (throw (Exception. (str "Don't know how to translate redirect"))))))) ^--- Don't know how to translate redirect 143: 144: 63 ;; here-string 145: (assoc opts :in (-> redir (get "Word") (get "Parts") only (get "Value"))) 146: ;; else 147: (do ----- Stack trace -------------------------------------------------------------- bash2bb.core - /home/me/.gitlibs/libs/io.github.pesterhazy/bash2bb/57c4f925273e2146b7ba8c392e3268775cef0616/src/bash2bb/core.clj:142:40 clojure.core/reduce - bash2bb.core/update-shell - /home/me/.gitlibs/libs/io.github.pesterhazy/bash2bb/57c4f925273e2146b7ba8c392e3268775cef0616/src/bash2bb/core.clj:122:27 bash2bb.core/update-shell - /home/me/.gitlibs/libs/io.github.pesterhazy/bash2bb/57c4f925273e2146b7ba8c392e3268775cef0616/src/bash2bb/core.clj:33:1 bash2bb.core/stmt->form - /home/me/.gitlibs/libs/io.github.pesterhazy/bash2bb/57c4f925273e2146b7ba8c392e3268775cef0616/src/bash2bb/core.clj:156:21 ... (run with --debug to see elided elements) bash2bb.core/bash->bb - /home/me/.gitlibs/libs/io.github.pesterhazy/bash2bb/57c4f925273e2146b7ba8c392e3268775cef0616/src/bash2bb/core.clj:246:23 bash2bb.core/bash->bb - /home/me/.gitlibs/libs/io.github.pesterhazy/bash2bb/57c4f925273e2146b7ba8c392e3268775cef0616/src/bash2bb/core.clj:245:1 bash2bb.core - /home/me/.gitlibs/libs/io.github.pesterhazy/bash2bb/57c4f925273e2146b7ba8c392e3268775cef0616/src/bash2bb/core.clj:259:16 clojure.core/apply - user ```

For comparison stdout redirect:

echo a | tee /dev/stderr > /dev/null

gets translated as:

(shell {:out "/dev/null", :in (:out (shell {:out :string} "echo" "a"))} "tee" "/dev/stderr")

I found out that babashka/process supports redirecting err to out with :err :out, so we could translate the initial repro as:

(shell {:out "/dev/null" :err :out :in (:out (shell {:out :string} "echo" "a"))} "tee" "/dev/stderr")
pesterhazy commented 1 year ago

Great bug report, thanks