package main
import (
"os/exec"
"fmt"
)
func main(){
cmd := exec.Command("find", "/home/d101270c/cbe", "-name","*.log", ">", "log.txt")
fmt.Println(cmd)
err := cmd.Run()
if err != nil {
fmt.Printf("%s\n", err)
return
}
}
运行结果:
<1067 linux20 [d101270c] :/home/d101270c>uname -a
Linux linux20 2.6.16.60-0.21-smp #1 SMP Tue May 6 12:41:02 UTC 2008 x86_64 x86_64 x86_64 GNU/Linux
<1068 linux20 [d101270c] :/home/d101270c>tgo
&{/usr/bin/find [find /home/d101270c/cbe -name *.log > log.txt] [] <nil> <nil> <nil> [] <nil> <nil> <nil> <nil> false [] [] [] [] <nil>}
exit status 1
该命令执行失败,不log.txt
存在。
为什么?