File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
9
9
10
10
### clojure
11
11
12
+ - [ Specify the Directory of a Shell Command] ( clojure/specify-the-directory-of-a-shell-command.md )
12
13
- [ Splitting On Whitespace] ( clojure/splitting-on-whitespace.md )
13
14
- [ Type of Anything] ( clojure/type-of-anything.md )
14
15
Original file line number Diff line number Diff line change
1
+ # Specify the Directory of a Shell Command
2
+
3
+ Clojure gives us access to Java's shell capabilities through
4
+ ` clojure.java.shell ` . For instance, if you want to list the contents of your
5
+ project's directory, you can issue an ` ls ` command:
6
+
7
+ ```
8
+ > (clojure.java.shell/sh "ls")
9
+ ; {:exit 0,
10
+ ; :out "LICENSE\nREADME.md\ndoc\nproject.clj\nresources\nsrc\ntarget\ntest\n",
11
+ ; :err ""}
12
+ ```
13
+
14
+ The default will always be to execute the command in the directory of the
15
+ containing project. It is likely that you'd like to specify a different
16
+ directory though. There is a function for that:
17
+
18
+ ``` clojure
19
+ (clojure.java.shell/with-sh-dir " some/dir" (clojure.java.shell/sh " ls" ))
20
+ ```
21
+
22
+ Or more concisely, you can specify the directory as part of the ` sh `
23
+ function:
24
+
25
+ ``` clojure
26
+ (clojure.java.shell/sh " ls" :dir " some/dir" )
27
+ ```
You can’t perform that action at this time.
0 commit comments