From d051de64e635afb22e314500dc02d3fd18b35018 Mon Sep 17 00:00:00 2001 From: Miki Tebeka Date: Wed, 1 May 2024 22:16:25 +0300 Subject: [PATCH] Option to redirect devserver stdout/stderr to a file (#1452) --- testsuite/devserver.go | 10 ++++++++++ testsuite/process_nonwindows.go | 3 ++- testsuite/process_windows.go | 4 +++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/testsuite/devserver.go b/testsuite/devserver.go index 23054fb6a..8b922a66f 100644 --- a/testsuite/devserver.go +++ b/testsuite/devserver.go @@ -77,6 +77,9 @@ type DevServerOptions struct { LogLevel string // Additional arguments to the dev server. ExtraArgs []string + // Where to redirect stdout and stderr, if nil they will be redirected to the current process. + Stdout io.Writer + Stderr io.Writer } // Temporal CLI based DevServer @@ -111,6 +114,13 @@ func StartDevServer(ctx context.Context, options DevServerOptions) (*DevServer, args := prepareCommand(&options, host, port, clientOptions.Namespace) cmd := newCmd(exePath, args...) + if options.Stdout != nil { + cmd.Stdout = options.Stdout + } + if options.Stderr != nil { + cmd.Stderr = options.Stderr + } + clientOptions.Logger.Info("Starting DevServer", "ExePath", exePath, "Args", args) if err := cmd.Start(); err != nil { return nil, fmt.Errorf("failed starting: %w", err) diff --git a/testsuite/process_nonwindows.go b/testsuite/process_nonwindows.go index bc51a82a5..03996f94d 100644 --- a/testsuite/process_nonwindows.go +++ b/testsuite/process_nonwindows.go @@ -33,7 +33,8 @@ import ( // newCmd creates a new command with the given executable path and arguments. func newCmd(exePath string, args ...string) *exec.Cmd { cmd := exec.Command(exePath, args...) - cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr return cmd } diff --git a/testsuite/process_windows.go b/testsuite/process_windows.go index 7e1b303db..123259876 100644 --- a/testsuite/process_windows.go +++ b/testsuite/process_windows.go @@ -37,7 +37,9 @@ func newCmd(exePath string, args ...string) *exec.Cmd { // isolate the process and signals sent to it from the current console CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP, } - cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + return cmd }