Fork me on GitHub
Chad kennedy21:12:51

I've got my project working great, under Windows. Only problem is that I have to modify the scripts in the project's package.json to call cmd-clojure instead of clojure. (I'be installed clojure via scoop) Is there a way to get clojure to be available from the cmd shell? This is a shared project with Linux users, so changing package.json isn't really an option.


@chad.kennedy I guess you could make a clojure.bat file which calls cmd-clojure and have that on that PATH

Chad kennedy21:12:19

It would have to pass through all the command line arguments as well. I'll give that a try.


shelling out to clojure has been a problem for me too in cmd.exe - nowadays I use bb clojure in CI which works the same in all environments


I think scoop's cmd-clojure seems to work under both cmd.exe and powershell - perhaps renaming or copying that to clojure.exe would solve the problem too

Chad kennedy21:12:22

Copying cmd-clojure.exe to clojure.exe didn't work. But creating a clojure.bat with the contents cmd-clojure %* worked a treat. Thanks for the suggestion! I have to say though the fact that I have to do things like this makes me think I must be going "against the grain" in terms of how I'm going about setting up my development environment. Does almost everyone doing Clojure just use Linux? Or am I missing something else?


Hi @chad.kennedy Author of scoop-clojure here. I read your suggestion But I'm sorry I won't add it. The reason is simple. It's already confusing enough in it's current form. But I have a suggestion 🙂 in a directory where you have package.json create both files clojure.bat and clj.bat with appropriate content. Then this basically works the way you want:

shelling $ ls

    Directory: C:\Users\alesn\Projects\shelling

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          27.12.2021    18:50             15 clojure.bat
-a---          27.12.2021    18:29            248 package.json

shelling $ cat .\clojure.bat
@cmd-clojure %*
shelling $ cat .\package.json
  "name": "shelling",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "clojure": "clojure"
  "keywords": [],
  "author": "",
  "license": "ISC"
shelling $ npm run clojure

> [email protected] clojure C:\Users\alesn\Projects\shelling
> clojure

Clojure 1.10.3


On Linux and Mac it will just run clojure from the platform specific place. On Windows it will run local .bat file.


I think so yes, and if you're on Windows, using WSL2 is also a popular option. But still there's "pure" Windows users too. Having a task runner call out to Clojure is maybe not so common, it's usually about invoking a REPL, which works fine under pure Windows.


There are some tools which fabricate some powershell incantation to call out to Clojure under Windows, I think shadow-cljs does this. But package.json scripts doesn't support OS-conditional commands.


A tool like babashka does support this in its task runner.

Chad kennedy21:12:42

Interesting. Thanks so much for your feedback and help!



{:tasks {compile (if (babashka.core/windows?) (shell "powershell.exe -command 'clojure ...') (shell "clojure ..."))}}
bb compile
or to use the built-in clojure CLI:
{:tasks {compile (clojure "...")}}

Chad kennedy21:12:31

Nice! Not sure that's an option for the shared project I'm working on, but I'll def keep it in mind for personal projects. Thanks for being so quick to help! Greatly appreciated!


@chad.kennedy Oh, it seems I was wrong about package.json, it does have some OS-specific thing:


It turned out there is a good solution to this:

npm config set script-shell "C:\\Program Files\\PowerShell\\7\\pwsh.exe"

# or yarn version
yarn config set script-shell "C:\\Program Files\\PowerShell\\7\\pwsh.exe"
Path above is my specific, can be on different place. Maybe the whole path is not even needed. now one can just run tasks on Windows the same way as on Unices.


It's good that @chad.kennedy came up. We are smarter every day.

Chad kennedy14:12:27

Glad I could bring some "beginner's mind" into the mix. 🙂


So you could use this and write powershell -command '...' perhaps

👍 1