Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1785314

Browse files
authored
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: #844 * Do not use NullWriter in executils by default. This is not strictly required for the 'avrdude' hack.
1 parent 9c9e25c commit 1785314

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

commands/upload/upload.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,6 @@ func runTool(recipeID string, props *properties.Map, outStream, errStream io.Wri
377377
return fmt.Errorf("cannot execute upload tool: %s", err)
378378
}
379379

380-
executils.AttachStdoutListener(cmd, executils.PrintToStdout)
381-
executils.AttachStderrListener(cmd, executils.PrintToStderr)
382380
cmd.Stdout = outStream
383381
cmd.Stderr = errStream
384382

executils/executils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,10 @@ func Command(args []string) (*exec.Cmd, error) {
8181
}
8282
cmd := exec.Command(args[0], args[1:]...)
8383
TellCommandNotToSpawnShell(cmd)
84+
85+
// This is required because some tools detects if the program is running
86+
// from terminal by looking at the stdin/out bindings.
87+
// https://github.com/arduino/arduino-cli/issues/844
88+
cmd.Stdin = NullReader
8489
return cmd, nil
8590
}

executils/null.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package executils
17+
18+
import "io"
19+
20+
// NullReader is an io.Reader that will always return EOF
21+
var NullReader = &nullReader{}
22+
23+
type nullReader struct{}
24+
25+
func (r *nullReader) Read(buff []byte) (int, error) {
26+
return 0, io.EOF
27+
}
28+
29+
// NullWriter is an io.Writer that discards any output
30+
var NullWriter = &nullWriter{}
31+
32+
type nullWriter struct{}
33+
34+
func (r *nullWriter) Write(buff []byte) (int, error) {
35+
return len(buff), nil
36+
}

0 commit comments

Comments
 (0)