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?

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Find more info on "cmd" here: learn.microsoft.com/en-us/windows-server/administration/… The "/C" flag tells Windows to "[Carry] out the command specified by string and then [stop]."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.