Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure CLI by

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

1 Answer

0 votes
by

It seems clj-deps (installable via scoop) and clj-msi don't have this problem:

Both install deps.clj (https://github.com/borkdude/deps.clj) as clj.exe and clojure.exe.

PS C:\Users\borkdude> Write-Output 'foo' | clojure -M -e '(println (slurp *in*))'
foo

PS C:\Users\borkdude> clj --version
Clojure CLI version (deps.clj) 1.11.1.1208
by
I did notice that! Though I wasn't aware of the scoop installer for fully replacing `clj` and `clojure` – I will definitely consider switching to that.
...