diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-06-30 15:34:22 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-06-30 15:34:22 +0200 |
commit | d39f5aa373a4422f7a5f3ee764fb0f6b0b719d61 (patch) | |
tree | 1833f8b72a4b3a8f00d0d143b079a8fcad01c6ae /src/pkg/syscall/exec_windows.go | |
parent | 8652e6c371b8905498d3d314491d36c58d5f68d5 (diff) | |
download | golang-d39f5aa373a4422f7a5f3ee764fb0f6b0b719d61.tar.gz |
Imported Upstream version 58upstream/58
Diffstat (limited to 'src/pkg/syscall/exec_windows.go')
-rw-r--r-- | src/pkg/syscall/exec_windows.go | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/pkg/syscall/exec_windows.go b/src/pkg/syscall/exec_windows.go index 85b1c2eda..b25f4a650 100644 --- a/src/pkg/syscall/exec_windows.go +++ b/src/pkg/syscall/exec_windows.go @@ -14,7 +14,7 @@ import ( var ForkLock sync.RWMutex -// escape rewrites command line argument s as prescribed +// EscapeArg rewrites command line argument s as prescribed // in http://msdn.microsoft.com/en-us/library/ms880421. // This function returns "" (2 double quotes) if s is empty. // Alternatively, these transformations are done: @@ -23,7 +23,7 @@ var ForkLock sync.RWMutex // - every double quote (") is escaped by back slash (\); // - finally, s is wrapped with double quotes (arg -> "arg"), // but only if there is space or tab inside s. -func escape(s string) string { +func EscapeArg(s string) string { if len(s) == 0 { return "\"\"" } @@ -89,7 +89,7 @@ func makeCmdLine(args []string) string { if s != "" { s += " " } - s += escape(v) + s += EscapeArg(v) } return s } @@ -222,6 +222,7 @@ type ProcAttr struct { Env []string Files []int HideWindow bool + CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess } var zeroAttributes ProcAttr @@ -252,10 +253,19 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid, handle int, } argv0p := StringToUTF16Ptr(argv0) + var cmdline string + // Windows CreateProcess takes the command line as a single string: + // use attr.CmdLine if set, else build the command line by escaping + // and joining each argument with spaces + if attr.CmdLine != "" { + cmdline = attr.CmdLine + } else { + cmdline = makeCmdLine(argv) + } + var argvp *uint16 - s := makeCmdLine(argv) - if len(s) != 0 { - argvp = StringToUTF16Ptr(s) + if len(cmdline) != 0 { + argvp = StringToUTF16Ptr(cmdline) } var dirp *uint16 |