Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
49 lines (38 sloc) 1.34 KB
// originally from:
class RunBash{
// Add a bash() method to GString and String
static def enable(){
GString.metaClass.bash = {->
String.metaClass.bash = {->
static def bash(cmd){
cmd = cmd as String
// create a process for the shell
ProcessBuilder pb = new ProcessBuilder("bash", "-c", cmd);
pb.redirectErrorStream(true); // use this to capture messages sent to stderr
Process shell = pb.start();
InputStream shellIn = shell.getInputStream(); // this captures the output from the command
// at this point you can process the output issued by the command
// for instance, this reads the output and writes it to System.out:
int c;
while ((c = != -1){
// this was before, but that meant that didn't see shell output
// until it was done... it does work here, right?
int shellExitStatus = shell.waitFor(); // wait for the shell to finish and get the return code
// close the stream
try {
pb = null;
shell = null;
} catch (IOException ignoreMe) {}
You can’t perform that action at this time.