Skip to content

os/exec: when NoInheritHandles is set with a handle on Stdout or Stderr, executed command fails #45538

@zhaoya881010

Description

@zhaoya881010

go version 1.16 windows/386

	out, err := os.OpenFile("test.out", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0766)
	c := exec.Command("cmd", "/C", "dir")
	c.Stdout = os.Stdout // OK
	//c.Stdout = out // Error
	c.SysProcAttr = &syscall.SysProcAttr{NoInheritHandles: true}
	c.Start()
	c.Wait()

if use c.Stdout = out,c.Wait() return error exit status 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Windows

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions