我用Go执行进程并将输出写入文件(日志文件)
原文链接:https://www.f2er.com/go/186857.htmlcmd := exec.Command(path) cmd.Dir = dir t := time.Now() t1 := t.Format("20060102-150405") fs,err := os.Create(dir + "/var/log/" + t1 + ".std") if err == nil { cmd.Stdout = fs }
我希望每天轮换日志并更改日志文件
http://golang.org/pkg/os/exec/
// Stdout and Stderr specify the process's standard output and error. // // If either is nil,Run connects the corresponding file descriptor // to the null device (os.DevNull). // // If Stdout and Stderr are the same writer,at most one // goroutine at a time will call Write. Stdout io.Writer Stderr io.Writer
从arbitary goroutine每天更改cmd.Stdout变量是否安全,或者我必须实现将从Stdout复制到另一个文件并切换文件的goroutine?