Skip to content

Fix tools tty detection (fix avrdude running in safe mode) #897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions commands/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions executils/executils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
36 changes: 36 additions & 0 deletions executils/null.go
Original file line number Diff line number Diff line change
@@ -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 [email protected].

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
}