Skip to content

Commit fb3f701

Browse files
committed
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
1 parent 95585ac commit fb3f701

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Diff for: executils/executils.go

+7
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,12 @@ 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.Stdout = NullWriter
89+
cmd.Stderr = NullWriter
90+
cmd.Stdin = NullReader
8491
return cmd, nil
8592
}

Diff for: executils/null.go

+36
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)