From cb56dfdbbf78dae1f8c82ac41eedc55aef644765 Mon Sep 17 00:00:00 2001 From: Kyle Larose Date: Mon, 15 Aug 2022 09:41:32 -0400 Subject: [PATCH] add Wait function to Launcher Some users of the public Launcher interface of the launcher package may want to wait for the launched process to exit. Support this by adding a Wait function to Launcher which waits on the process to terminate. --- launcher/jnlp/launcher.go | 9 +++++++++ launcher/launcher.go | 2 ++ 2 files changed, 11 insertions(+) diff --git a/launcher/jnlp/launcher.go b/launcher/jnlp/launcher.go index 42ea128..4eb67ee 100644 --- a/launcher/jnlp/launcher.go +++ b/launcher/jnlp/launcher.go @@ -129,6 +129,15 @@ func (launcher *Launcher) Terminate() { } } +// Wait waits for the executed command to exit +func (launcher *Launcher) Wait() (*os.ProcessState, error) { + if launcher.cmd == nil || launcher.cmd.Process == nil { + return nil, errors.New("process not running") + } + + return launcher.cmd.Process.Wait() +} + func (launcher *Launcher) CheckPlatform() error { if err := settings.EnsureJavaExecutableAvailability(); err != nil { return errors.Wrap(err, "java executable wasn't found") diff --git a/launcher/launcher.go b/launcher/launcher.go index f0918d4..629948d 100644 --- a/launcher/launcher.go +++ b/launcher/launcher.go @@ -2,6 +2,7 @@ package launcher import ( "net/url" + "os" "strings" "github.com/pkg/errors" @@ -21,6 +22,7 @@ type Launcher interface { UninstallByFilename(filename string, showGUI bool) error UninstallByURL(url string, showGUI bool) error SetLogFile(logFile string) + Wait() (*os.ProcessState, error) } type Options struct {