Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run shell command in Clojure from specific location

Tags:

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.

like image 289
MRocklin Avatar asked Sep 06 '12 00:09

MRocklin


1 Answers

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.

like image 198
Dave Ray Avatar answered Oct 07 '22 10:10

Dave Ray