From 913c8d73978795e4f2cdd1f87de3af5239ebdc84 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Thu, 24 Mar 2011 11:20:28 +1100 Subject: syscall: StartProcess fixes for windows - StartProcess will work with relative (to attr.Dir, not current directory) executable filenames - StartProcess will only work if executable filename points to the real file, it will not search for executable in the $PATH list and others (see CreateProcess manual for details) - StartProcess argv strings can contain any characters R=golang-dev, r CC=golang-dev https://golang.org/cl/4306041 --- src/pkg/exec/exec_test.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'src/pkg/exec') diff --git a/src/pkg/exec/exec_test.go b/src/pkg/exec/exec_test.go index 3a3d3b1a53..5e37b99eec 100644 --- a/src/pkg/exec/exec_test.go +++ b/src/pkg/exec/exec_test.go @@ -118,3 +118,55 @@ func TestAddEnvVar(t *testing.T) { t.Fatal("close:", err) } } + +var tryargs = []string{ + `2`, + `2 `, + "2 \t", + `2" "`, + `2 ab `, + `2 "ab" `, + `2 \ `, + `2 \\ `, + `2 \" `, + `2 \`, + `2\`, + `2"`, + `2\"`, + `2 "`, + `2 \"`, + ``, + `2 ^ `, + `2 \^`, +} + +func TestArgs(t *testing.T) { + for _, a := range tryargs { + argv := []string{ + "awk", + `BEGIN{printf("%s|%s|%s",ARGV[1],ARGV[2],ARGV[3])}`, + "/dev/null", + a, + "EOF", + } + exe, err := LookPath(argv[0]) + if err != nil { + t.Fatal("run:", err) + } + cmd, err := Run(exe, argv, nil, "", DevNull, Pipe, DevNull) + if err != nil { + t.Fatal("run:", err) + } + buf, err := ioutil.ReadAll(cmd.Stdout) + if err != nil { + t.Fatal("read:", err) + } + expect := "/dev/null|" + a + "|EOF" + if string(buf) != expect { + t.Errorf("read: got %q expect %q", buf, expect) + } + if err = cmd.Close(); err != nil { + t.Fatal("close:", err) + } + } +} -- cgit v1.3