GO語言"os/exec"包中"Cmd.StdinPipe"類型的用法及代碼示例。
用法:
func(c *Cmd) StdinPipe()(io.WriteCloser, error)
StdinPipe 返回一個管道,該管道將在命令啟動時連接到命令的標準輸入。 Wait 看到命令退出後,管道將自動關閉。調用者隻需調用 Close 即可強製管道更快關閉。例如,如果正在運行的命令在標準輸入關閉之前不會退出,則調用者必須關閉管道。
例子:
package main
import (
"fmt"
"io"
"log"
"os/exec"
)
func main() {
cmd := exec.Command("cat")
stdin, err := cmd.StdinPipe()
if err != nil {
log.Fatal(err)
}
go func() {
defer stdin.Close()
io.WriteString(stdin, "values written to stdin are passed to cmd's standard input")
}()
out, err := cmd.CombinedOutput()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", out)
}
相關用法
- GO Cmd.StderrPipe用法及代碼示例
- GO Cmd.StdoutPipe用法及代碼示例
- GO Cmd.Start用法及代碼示例
- GO Cmd.Output用法及代碼示例
- GO Cmd.Run用法及代碼示例
- GO Cmd.CombinedOutput用法及代碼示例
- GO Chmod用法及代碼示例
- GO CanBackquote用法及代碼示例
- GO CopyN用法及代碼示例
- GO CopyBuffer用法及代碼示例
- GO CreateTemp用法及代碼示例
- GO Cut用法及代碼示例
- GO CIDRMask用法及代碼示例
- GO ContainsRune用法及代碼示例
- GO Cbrt用法及代碼示例
- GO Copysign用法及代碼示例
- GO Compare用法及代碼示例
- GO Cosh用法及代碼示例
- GO Config用法及代碼示例
- GO Count用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Cmd.StdinPipe。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。