Black Lives Matter. Support the Equal Justice Initiative.

Source file src/os/exec/exec_windows_test.go

Documentation: os/exec

     1  // Copyright 2021 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build windows
     6  // +build windows
     7  
     8  package exec_test
     9  
    10  import (
    11  	"io"
    12  	"os"
    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  

View as plain text