golang中os/exec包用法

pull/5/head
ShaoBo Wan 7 years ago
parent f6ca8eda41
commit 94a31fb7ff

@ -2,10 +2,24 @@ package main
import ( import (
"fmt" "fmt"
"os"
"os/exec"
"github.com/Tinywan/golang-tutorial/stringutil" "github.com/Tinywan/golang-tutorial/stringutil"
) )
func main() { func main() {
//fmt.Println("Hello golang-tutorial!") //fmt.Println("Hello golang-tutorial!")
fmt.Printf(stringutil.Reverse("!oG ,olleH")) 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()
} }
Loading…
Cancel
Save