Skip to content

Instantly share code, notes, and snippets.

@develar
Created December 30, 2015 20:16
Show Gist options
  • Save develar/c274d4f5898e8119bb68 to your computer and use it in GitHub Desktop.
Save develar/c274d4f5898e8119bb68 to your computer and use it in GitHub Desktop.
fun runAndWait(commandLine: GeneralCommandLine) {
val handler = KillableColoredProcessHandler(commandLine, true)
var hasErrors = false
handler.addProcessListener(object : ProcessAdapter() {
override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) {
val text = event.text
// https://github.com/maxogden/electron-packager/pull/228
val out = if (outputType == ProcessOutputTypes.STDERR && !text.startsWith("Packaging app for platform ")) {
hasErrors = true
System.err
}
else {
System.out
}
out.println(text)
}
})
handler.startNotify()
// "meteor update" take a lot of time on linux
if (!handler.waitFor((10 * Time.MINUTE).toLong())) {
try {
handler.destroyProcess()
}
finally {
throw AssertionError("'${commandLine.commandLineString}' is not completed in 10 minutes, terminated")
}
}
if (hasErrors) {
throw AssertionError("'${commandLine.commandLineString}' has error output")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment