1 回答

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
刪除io.Copy不重定向到 STDOUT 并打印緩沖區(qū)的內(nèi)容。
systemCmd := exec.Command("systeminfo")
findCmd := exec.Command("findstr", "/B", "/C:OS Name")
reader, writer := io.Pipe()
buf := bytes.NewBuffer(nil)
systemCmd.Stdout = writer
findCmd.Stdin = reader
findCmd.Stdout = buf
systemCmd.Start()
findCmd.Start()
systemCmd.Wait()
writer.Close()
findCmd.Wait()
reader.Close()
fmt.Println(">>" + buf.String())
IE:
PS C:\Users\user\Documents> go run .\main.go
>>OS Name: Microsoft Windows 10 Pro
- 1 回答
- 0 關(guān)注
- 109 瀏覽
添加回答
舉報(bào)