title: Running shell command from Gradle script
body: <p>I am having the darndest time trying to figure out how to run a shell command from Gradle, since it seems like Gradle makes it very difficult to do this. </p>
  
  <p>Here is the command:</p>
  
  <pre><code>git branch --merged | grep -v \* | grep -v master | grep -v develop | grep -v dmz | xargs git branch -D
  </code></pre>
  
  <p>It's just a convenience command to clean up local branches that have been merged. </p>
  
  <p>Here is the task I created:</p>
  
  <pre><code>task gitCleanLocalBranches {
      doLast {
          exec {
              workingDir '.'
              commandLine 'git branch --merged | grep -v \\* | grep -v master | grep -v develop | grep -v dmz | xargs git branch -D'
  
          }
      }
  }
  </code></pre>
  
  <p>The task fails with:</p>
  
  <pre><code>FAILURE: Build failed with an exception.
  
  * What went wrong:
  Execution failed for task ':gitCleanLocalBranches'.
  &gt; A problem occurred starting process 'command 'git branch -a''
  
  * Try:
  Run with --info or --debug option to get more log output.
  
  * Exception is:
  org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':gitCleanLocalBranches'.
          at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
          ...
  Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'git branch --merged | grep -v \* | grep -v master | grep -v develop | grep -v dmz | xargs git branch -D''
          at org.gradle.process.internal.DefaultExecHandle.execExceptionFor(DefaultExecHandle.java:222)
          ... 3 more
  Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'git branch --merged | grep -v \* | grep -v master | grep -v develop | grep -v dmz | xargs git branch -D'
          at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
          ... 4 more
  Caused by: java.io.IOException: Cannot run program "git branch --merged | grep -v \* | grep -v master | grep -v develop | grep -v dmz | xargs git branch -D" (in directory "/home/wlaw/sterlib"): error=2, No such file or directory
          at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
          ... 6 more
  Caused by: java.io.IOException: error=2, No such file or directory
          ... 7 more
  </code></pre>
  
  <p>So I figured that the command is too complicated so I tried something simpler, and changed <code>commandLine</code> to:</p>
  
  <pre><code>commandLine 'git branch -a'
  </code></pre>
  
  <p>But I got the exact same error. Why is Gradle not able to find anything in the <code>PATH</code> environment variable?</p>