On Powershell, when you run the command
Write-Output 'foo' | clojure -M -e '(println (slurp *in*))'
the process hangs and waits for interactive input, rather than printing the piped input.
This seems to be because the calls to java
in the Powershell implementation of clj
/clojure
do not explicitly hand over $Input
when it is bound.
Based on this discussion on a similar issue, this proof of concept demonstrates a potential fix:
PS> Get-Content clj.ps1
if ($MyInvocation.ExpectingInput) {
$Input | java -classpath "$(clojure -Spath)" clojure.main -e '(println (slurp *in*))'
} else {
java -classpath "$(clojure -Spath)" clojure.main -e '(println (slurp *in*))'
}
PS> Write-Output 'foo' | .\clj.ps1
foo
PS> .\clj.ps1
This text was supplied interactively, followed by a ^C
This text was supplied interactively, followed by a ^C
PS>
h/t @hiredman on the Clojurians Slack for finding that GitHub discussion