duanbishai5271
2012-07-24 02:22
浏览 670
已采纳

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
", err)
        return
    }
}

Run result:

<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

This command execute failed, and no log.txt exists.

Why?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题