2

I'm trying to run a Windows command from a Clojure program. I am testing it with a small echo statement:

(:require [clojure.java.shell :as sh])

(defn testcal [cob]
  (let [cmd (str "echo hi" )
        result (sh/sh cmd)]))

Its throwing me the following error:

Exception in thread "main" java.io.IOException: Cannot run program "echo hi": CreateProcess error=2, The system cannot find the file specified

My java path looks good and checked everything. Can someone help me with this?

Richard Erickson
  • 2,568
  • 8
  • 26
  • 39
Sri
  • 573
  • 2
  • 6
  • 20

1 Answers1

2

in windows environment, instead of

(sh/sh "echo hi")

try

(sh/sh "cmd" "/C" "echo hi")

the answer of why "cmd" "/C" is here https://stackoverflow.com/a/4031412/1393248

Community
  • 1
  • 1
mavbozo
  • 1,161
  • 8
  • 10
  • Find more info on "cmd" here: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmd The "/C" flag tells Windows to "[Carry] out the command specified by string and then [stop]." – Aaron Bell Jan 07 '23 at 09:32