github.com/gogf/gf/v2@v2.7.4/os/gproc/testdata/shellexec/main.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package main 8 9 import ( 10 "flag" 11 "fmt" 12 "os" 13 ) 14 15 func main() { 16 var content string 17 var output string 18 flag.StringVar(&content, "c", "", "写入内容") 19 flag.StringVar(&output, "o", "", "写入路径") 20 flag.Parse() 21 fmt.Println(os.Args) 22 fmt.Println(content) 23 fmt.Println(output) 24 if output != "" { 25 file, err := os.Create(output) 26 if err != nil { 27 panic("create file fail: " + err.Error()) 28 } 29 defer file.Close() 30 file.WriteString(content) 31 } 32 }