dundalek / closh

Bash-like shell based on Clojure
Eclipse Public License 1.0
1.61k stars 65 forks source link

Redirects do not work correctly when reassigning std descriptors #165

Open dundalek opened 4 years ago

dundalek commented 4 years ago

In bash following prints nothing:

bash -c "echo x 1>&2" 2>/dev/null

In closh following prints x:

clojure -m closh.zero.frontend.rebel -e "echo x 1 >& 2" 2>/dev/null

I am not sure if it is possible to bend ProbessBuilder to make it work. We likely need to reach for lower level native APIs.

Some test cases:

(are [x y] (= (bash x) (closh-spawn y))
    "echo x 1>&2"
    "echo x 1 >& 2"

    "bash -c \"echo err 1>&2; echo out\" 2>&1"
    "bash -c \"echo err 1>&2; echo out\" 2 >& 1"

    "bash -c \"echo err 1>&2; echo out\" 2>&1 | cat"
    "bash -c \"echo err 1>&2; echo out\" 2 >& 1 | cat")