You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2019/01/17 19:32:56 UTC
[mynewt-newt] branch master updated: Escape '{' and '}' in command
line args in Windows
This is an automated email from the ASF dual-hosted git repository.
janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git
The following commit(s) were added to refs/heads/master by this push:
new a7559e3 Escape '{' and '}' in command line args in Windows
new d1706c5 Merge pull request #259 from ccollins476ad/windows-curly
a7559e3 is described below
commit a7559e35917deea2ea2d79f8b91a159424258d36
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Jan 16 18:50:35 2019 -0800
Escape '{' and '}' in command line args in Windows
(Windows-only)
Escape '{' and '}' with backslashes in command line arguments. Without
this change, curly braces mysteriously disappear from commands passed to
`exec.Command`.
---
util/util.go | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/util/util.go b/util/util.go
index b1d7973..862f3fe 100644
--- a/util/util.go
+++ b/util/util.go
@@ -261,6 +261,16 @@ func Init(logLevel log.Level, logFile string, verbosity int) error {
return nil
}
+// Escapes special characters for Windows builds.
+func fixupCmdArgs(args []string) {
+ if runtime.GOOS == "windows" {
+ for i, _ := range args {
+ args[i] = strings.Replace(args[i], "{", "\\{", -1)
+ args[i] = strings.Replace(args[i], "}", "\\}", -1)
+ }
+ }
+}
+
func LogShellCmd(cmdStrs []string, env []string) {
envLogStr := ""
if len(env) > 0 {
@@ -298,6 +308,9 @@ func ShellCommandLimitDbgOutput(
var name string
var args []string
+ // Escape special characters for Windows.
+ fixupCmdArgs(cmdStrs)
+
if logCmd {
LogShellCmd(cmdStrs, env)
}
@@ -353,12 +366,13 @@ func ShellCommand(cmdStrs []string, env []string) ([]byte, error) {
// Run interactive shell command
func ShellInteractiveCommand(cmdStr []string, env []string) error {
+ // Escape special characters for Windows.
+ fixupCmdArgs(cmdStr)
+
log.Print("[VERBOSE] " + cmdStr[0])
- //
// Block SIGINT, at least.
// Otherwise Ctrl-C meant for gdb would kill newt.
- //
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
signal.Notify(c, syscall.SIGTERM)