From 95585ac6ea6a5be545db1862f573db3a8fd864bf Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 14 Aug 2020 14:36:53 +0200 Subject: [PATCH 1/3] Removed useless stdout/err listeners They are immediatly overwritten on the next line. --- commands/upload/upload.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/commands/upload/upload.go b/commands/upload/upload.go index 0fc94dfcb98..373efbc6ae0 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -377,8 +377,6 @@ func runTool(recipeID string, props *properties.Map, outStream, errStream io.Wri return fmt.Errorf("cannot execute upload tool: %s", err) } - executils.AttachStdoutListener(cmd, executils.PrintToStdout) - executils.AttachStderrListener(cmd, executils.PrintToStderr) cmd.Stdout = outStream cmd.Stderr = errStream From fb3f701ee5bee849196fd5c44207659edb711c80 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 14 Aug 2020 14:37:53 +0200 Subject: [PATCH 2/3] Always pipe stdout/err/in when running tools. This is required because some tools detects if the program is running from terminal by looking at the stdin/out bindings. Fix: https://github.com/arduino/arduino-cli/issues/844 --- executils/executils.go | 7 +++++++ executils/null.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 executils/null.go diff --git a/executils/executils.go b/executils/executils.go index 6804cc2da6c..9e2739fa55d 100644 --- a/executils/executils.go +++ b/executils/executils.go @@ -81,5 +81,12 @@ func Command(args []string) (*exec.Cmd, error) { } cmd := exec.Command(args[0], args[1:]...) TellCommandNotToSpawnShell(cmd) + + // This is required because some tools detects if the program is running + // from terminal by looking at the stdin/out bindings. + // https://github.com/arduino/arduino-cli/issues/844 + cmd.Stdout = NullWriter + cmd.Stderr = NullWriter + cmd.Stdin = NullReader return cmd, nil } diff --git a/executils/null.go b/executils/null.go new file mode 100644 index 00000000000..e0bb37e75b1 --- /dev/null +++ b/executils/null.go @@ -0,0 +1,36 @@ +// This file is part of arduino-cli. +// +// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) +// +// This software is released under the GNU General Public License version 3, +// which covers the main part of arduino-cli. +// The terms of this license can be found at: +// https://www.gnu.org/licenses/gpl-3.0.en.html +// +// You can be released from the requirements of the above licenses by purchasing +// a commercial license. Buying such a license is mandatory if you want to +// modify or otherwise use the software for commercial activities involving the +// Arduino software without disclosing the source code of your own applications. +// To purchase a commercial license, send an email to license@arduino.cc. + +package executils + +import "io" + +// NullReader is an io.Reader that will always return EOF +var NullReader = &nullReader{} + +type nullReader struct{} + +func (r *nullReader) Read(buff []byte) (int, error) { + return 0, io.EOF +} + +// NullWriter is an io.Writer that discards any output +var NullWriter = &nullWriter{} + +type nullWriter struct{} + +func (r *nullWriter) Write(buff []byte) (int, error) { + return len(buff), nil +} From 82a957f99e479ddc9e3a95b8c9bb261a20531e98 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 17 Aug 2020 11:33:16 +0200 Subject: [PATCH 3/3] Do not use NullWriter in executils by default. This is not strictly required for the 'avrdude' hack. --- executils/executils.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/executils/executils.go b/executils/executils.go index 9e2739fa55d..44fbff0f08a 100644 --- a/executils/executils.go +++ b/executils/executils.go @@ -85,8 +85,6 @@ func Command(args []string) (*exec.Cmd, error) { // This is required because some tools detects if the program is running // from terminal by looking at the stdin/out bindings. // https://github.com/arduino/arduino-cli/issues/844 - cmd.Stdout = NullWriter - cmd.Stderr = NullWriter cmd.Stdin = NullReader return cmd, nil }