From 94a31fb7ffbbef7e360ce740072edabf8d6a8972 Mon Sep 17 00:00:00 2001 From: ShaoBo Wan Date: Mon, 2 Apr 2018 22:54:49 +0800 Subject: [PATCH] =?UTF-8?q?golang=E4=B8=ADos/exec=E5=8C=85=E7=94=A8?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/main.go b/main.go index 5ef6b4c..de5c768 100644 --- a/main.go +++ b/main.go @@ -2,10 +2,24 @@ package main import ( "fmt" + "os" + "os/exec" "github.com/Tinywan/golang-tutorial/stringutil" ) func main() { //fmt.Println("Hello golang-tutorial!") fmt.Printf(stringutil.Reverse("!oG ,olleH")) + cmd := exec.Command("pwd") + stdin,err :=cmd.StdinPipe(); + if err != nil { + fmt.Println(err) + } + _,err = stdin.Write([]byte("tmp.txt")) + if err != nil { + fmt.Println(err) + } + stdin.Close() + cmd.Stdout = os.Stdout //终端标准输出tmp.txt + cmd.Start() } \ No newline at end of file