MRocklin
MRocklin

Reputation: 57261

Run shell command in Clojure from specific location

I would like to read the output of a shell command. The shell command I want to read must be run from a specific location. (it's git log).

Is there a nice way to do this other than cding into the location, running (clojure.java.shell/sh "git log"), and then cding back to the working directory?

I'm looking for some sort of (shell-at directory command) function. A simple implementation of this function would also be appreciated. My experience with Clojure is minimal.

Upvotes: 23

Views: 2320

Answers (1)

Dave Ray
Dave Ray

Reputation: 40005

clojure.java.shell/sh supports a :dir option to set the working directory of the sub-process:

(clojure.java.shell/sh "git" "log" :dir "/path/to/some/directory")

See here.

Upvotes: 31

Related Questions