Source file
src/os/exec/exec_windows_test.go
1
2
3
4
5
6
7 package exec_test
8
9 import (
10 "io"
11 "os"
12 "os/exec"
13 "strconv"
14 "syscall"
15 "testing"
16 )
17
18 func TestPipePassing(t *testing.T) {
19 r, w, err := os.Pipe()
20 if err != nil {
21 t.Error(err)
22 }
23 const marker = "arrakis, dune, desert planet"
24 childProc := helperCommand(t, "pipehandle", strconv.FormatUint(uint64(w.Fd()), 16), marker)
25 childProc.SysProcAttr = &syscall.SysProcAttr{AdditionalInheritedHandles: []syscall.Handle{syscall.Handle(w.Fd())}}
26 err = childProc.Start()
27 if err != nil {
28 t.Error(err)
29 }
30 w.Close()
31 response, err := io.ReadAll(r)
32 if err != nil {
33 t.Error(err)
34 }
35 r.Close()
36 if string(response) != marker {
37 t.Errorf("got %q; want %q", string(response), marker)
38 }
39 err = childProc.Wait()
40 if err != nil {
41 t.Error(err)
42 }
43 }
44
45 func TestNoInheritHandles(t *testing.T) {
46 cmd := exec.Command("cmd", "/c exit 88")
47 cmd.SysProcAttr = &syscall.SysProcAttr{NoInheritHandles: true}
48 err := cmd.Run()
49 exitError, ok := err.(*exec.ExitError)
50 if !ok {
51 t.Fatalf("got error %v; want ExitError", err)
52 }
53 if exitError.ExitCode() != 88 {
54 t.Fatalf("got exit code %d; want 88", exitError.ExitCode())
55 }
56 }
57
View as plain text