From fdde14efdbd23d6f71af1b413c6bebea8075d18f Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sun, 5 Apr 2015 12:20:31 -0500 Subject: [PATCH] Add Specify the Directory of a Shell Command as a clojure til. --- README.md | 1 + ...pecify-the-directory-of-a-shell-command.md | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 clojure/specify-the-directory-of-a-shell-command.md diff --git a/README.md b/README.md index 6867909..fe7c320 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ smart people at [Hashrocket](http://hashrocket.com/). ### clojure +- [Specify the Directory of a Shell Command](clojure/specify-the-directory-of-a-shell-command.md) - [Splitting On Whitespace](clojure/splitting-on-whitespace.md) - [Type of Anything](clojure/type-of-anything.md) diff --git a/clojure/specify-the-directory-of-a-shell-command.md b/clojure/specify-the-directory-of-a-shell-command.md new file mode 100644 index 0000000..f001228 --- /dev/null +++ b/clojure/specify-the-directory-of-a-shell-command.md @@ -0,0 +1,27 @@ +# Specify the Directory of a Shell Command + +Clojure gives us access to Java's shell capabilities through +`clojure.java.shell`. For instance, if you want to list the contents of your +project's directory, you can issue an `ls` command: + +``` +> (clojure.java.shell/sh "ls") +; {:exit 0, +; :out "LICENSE\nREADME.md\ndoc\nproject.clj\nresources\nsrc\ntarget\ntest\n", +; :err ""} +``` + +The default will always be to execute the command in the directory of the +containing project. It is likely that you'd like to specify a different +directory though. There is a function for that: + +```clojure +(clojure.java.shell/with-sh-dir "some/dir" (clojure.java.shell/sh "ls")) +``` + +Or more concisely, you can specify the directory as part of the `sh` +function: + +```clojure +(clojure.java.shell/sh "ls" :dir "some/dir") +```