猿问

Go语言的exec.Command方法执行失败

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存在。


为什么?


郎朗坤
浏览 493回答 2
2回答
随时随地看视频慕课网APP

相关分类

Go
我要回答