diff --git a/launcher/jnlp/launcher.go b/launcher/jnlp/launcher.go index 42ea128..60be4aa 100644 --- a/launcher/jnlp/launcher.go +++ b/launcher/jnlp/launcher.go @@ -299,6 +299,22 @@ func (launcher *Launcher) exec() error { if launcher.gui.Closed() { return errCancelled } + + if launcher.options != nil && launcher.options.StdoutHandler != nil { + pipe, err := cmd.StdoutPipe() + if err != nil { + return errors.Wrap(err, "failed to create stdout pipe to application") + } + go launcher.options.StdoutHandler(pipe) + } + + if launcher.options != nil && launcher.options.StderrHandler != nil { + pipe, err := cmd.StderrPipe() + if err != nil { + return errors.Wrap(err, "failed to create stderr pipe to application") + } + go launcher.options.StderrHandler(pipe) + } return cmd.Start() } diff --git a/launcher/launcher.go b/launcher/launcher.go index f0918d4..aa21745 100644 --- a/launcher/launcher.go +++ b/launcher/launcher.go @@ -1,6 +1,7 @@ package launcher import ( + "io" "net/url" "strings" @@ -23,12 +24,22 @@ type Launcher interface { SetLogFile(logFile string) } +// OutputHandler is invoked with the read end of a pipe to which the Launcher forwards +// output (stdout or stderr). Each instance of an OutputHandler will be provided its own +// goroutine, so it may block as necessary. +type OutputHandler = func(pipe io.ReadCloser) + type Options struct { IsRunningFromBrowser bool JavaDir string ShowConsole bool DisableVerification bool DisableVerificationSameOrigin bool + + // If non-nil, processes output from stdout of the launched process + StdoutHandler OutputHandler + // If non-nil, processes output from stderr of the launched process + StderrHandler OutputHandler } func RegisterProtocol(scheme string, launcher Launcher) {