Unverified Commit 1785314e authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

Always redirect stdin to null (fix tools tty detection, in particular avrdude...

Always redirect stdin to null (fix tools tty detection, in particular avrdude running in safe mode) (#897)

Some tools detects if the program is running from terminal by looking at the stdin/out bindings.
Previously stdin wasn't bound to any custom stream, this fact lead avrdude to think it was run from terminal (instead of a script) and start it in "safe-mode". This turn out to be a problem in some cases, see #844

* Removed useless stdout/err listeners

They are immediatly overwritten on the next line.

* 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

* Do not use NullWriter in executils by default.

This is not strictly required for the 'avrdude' hack.
parent 9c9e25cb
......@@ -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
......
......@@ -81,5 +81,10 @@ 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.Stdin = NullReader
return cmd, nil
}
// 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
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment