cmd.StdoutPipe go pkg 文档中的示例在 playground 中没有 运行

cmd.StdoutPipe example in go pkg docs does not run in playground

cmd.StdoutPipe go 文档中的示例:https://pkg.go.dev/os/exec#example-Cmd.StdoutPipe 在 playground 中不 运行。

https://play.golang.org/p/ek7-_Xa_bN3

错误:

fatal error: all goroutines are asleep - deadlock!

goroutine 1 [IO wait]:
internal/poll.runtime_pollWait(0x7faec2ac4e88, 0x72)
    /usr/local/go-faketime/src/runtime/netpoll.go:234 +0x89
internal/poll.(*pollDesc).wait(0xc000074180, 0xc000100000, 0x1)
    /usr/local/go-faketime/src/internal/poll/fd_poll_runtime.go:84 +0x32
internal/poll.(*pollDesc).waitRead(...)
    /usr/local/go-faketime/src/internal/poll/fd_poll_runtime.go:89
internal/poll.(*FD).Read(0xc000074180, {0xc000100000, 0x200, 0x200})
    /usr/local/go-faketime/src/internal/poll/fd_unix.go:167 +0x25a
os.(*File).read(...)
    /usr/local/go-faketime/src/os/file_posix.go:32
os.(*File).Read(0xc00000e028, {0xc000100000, 0x28, 0xc000060e80})
    /usr/local/go-faketime/src/os/file.go:119 +0x5e
encoding/json.(*Decoder).refill(0xc00007e000)
    /usr/local/go-faketime/src/encoding/json/stream.go:165 +0x17f
encoding/json.(*Decoder).readValue(0xc00007e000)
    /usr/local/go-faketime/src/encoding/json/stream.go:140 +0xbb
encoding/json.(*Decoder).Decode(0xc00007e000, {0x4cf580, 0xc00000c048})
    /usr/local/go-faketime/src/encoding/json/stream.go:63 +0x78
main.main()
    /tmp/sandbox2294589397/prog.go:24 +0x185

Program exited.

本地 运行ning 正确,没有死锁。我无法理解为什么在 go playground 中会发生死锁。

来自 os.exec package 上的文档(这是此示例的来源):

Note that the examples in this package assume a Unix system. They may not run on Windows, and they do not run in the Go Playground used by golang.org and godoc.org.

该说明没有提供原因,但原因大概是允许 user-provided unix 命令到 运行 会给恶意代码提供更广泛的攻击面。这并不是说不可能以一种相对安全的方式允许这样做,但是有各种权衡使得不允许 os.exec 成为一个自然的选择。