Skip to content

Commit 1d15354

Browse files
committed
os/exec: document how to do special args quoting on Windows
Updates #27199 Change-Id: I5cb6540266901697d3558ce75b8de63b1bfc2ce0 Reviewed-on: https://go-review.googlesource.com/132695 Reviewed-by: Alex Brainman <[email protected]>
1 parent 579768e commit 1d15354

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/os/exec/exec.go

+9
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ type Cmd struct {
152152
// followed by the elements of arg, so arg should not include the
153153
// command name itself. For example, Command("echo", "hello").
154154
// Args[0] is always name, not the possibly resolved Path.
155+
//
156+
// On Windows, processes receive the whole command line as a single string
157+
// and do their own parsing. Command combines and quotes Args into a command
158+
// line string with an algorithm compatible with applications using
159+
// CommandLineToArgvW (which is the most common way). Notable exceptions are
160+
// msiexec.exe and cmd.exe (and thus, all batch files), which have a different
161+
// unquoting algorithm. In these or other similar cases, you can do the
162+
// quoting yourself and provide the full command line in SysProcAttr.CmdLine,
163+
// leaving Args empty.
155164
func Command(name string, arg ...string) *Cmd {
156165
cmd := &Cmd{
157166
Path: name,

0 commit comments

Comments
 (0)