我有一个命令,我通过Stdin向其发送数据,并期望有28个输出流(包括
Stdout
).
所以我想用
cmd.ExtraFiles
带有a的字段
os.Pipe
对于每一个
os.ExtraFiles
.
我写了以下内容:
backgroundContext, cancelCommand := context.WithCancel(context.Background())
cmd := exec.CommandContext(backgroundContext, "command", args...)
cmd.ExtraFiles = make([]*io.File, 27, 0)
var outputPipe io.ReadCloser
var inputPipe io.WriteCloser
outputPipe, inputPipe, err = os.Pipe()
cmd.ExtraFiles[0] = &inputPipe
cmd.ExtraFiles[1] = &outputPipe
最后两行生成错误,因为类型不匹配:
./main.go:876:26: cannot use &inputPipe (type *io.WriteCloser) as type *os.File in assignment
./main.go:877:26: cannot use &outputPipe (type *io.ReadCloser) as type *os.File in assignment
我确信我们可以分配管道,因为例如我可以使用
StdoutPipe()
功能正常,工作正常。
我该怎么做
os。附加文件
?