Skip to content

Instantly share code, notes, and snippets.

@katta
Created April 26, 2013 06:09
  • Star 21 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Groovy shell command
def command = "git --version"
def proc = command.execute()
proc.waitFor()
println "Process exit code: ${proc.exitValue()}"
println "Std Err: ${proc.err.text}"
println "Std Out: ${proc.in.text}"
@marslo
Copy link

marslo commented Apr 23, 2021

with git working dir:

String command = "git log -1"
def proc = command.execute( null, new File("/path/to/folder") )
proc.waitFor()              

println """
  ${proc.err.text ?: ''}
  ${proc.in.text ?: ''}
  Process exit code: ${proc.exitValue()}
"""

or with system environment

List env = System.getenv().collect { k, v -> "${k}=${v}" }
String command = "git log -1"
def proc = command.execute( env, new File("/path/to/folder") )
proc.waitFor()  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment