Skip to content

Instantly share code, notes, and snippets.

@joutvhu
Last active November 20, 2020 15:03
Show Gist options
  • Save joutvhu/21be89cda154cce8c33936aa1866ce65 to your computer and use it in GitHub Desktop.
Save joutvhu/21be89cda154cce8c33936aa1866ce65 to your computer and use it in GitHub Desktop.
def commandLineOf(command, terminal = null) {
    if (System.properties['os.name'].toLowerCase().contains('windows')) {
        return ['cmd', '/c', command]
    } else if (terminal != null) {
        return ['bash', '-c', terminal]
    } else {
        return ['bash', '-c', command]
    }
}

task example {
    doLast {
        exec {
            workingDir '.'
            commandLine commandLineOf("git fetch")
        }
        exec {
            workingDir '.'
            commandLine commandLineOf("dir", "ls")
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment