为什么我从golang运行python脚本错误

时间:2017-11-13 02:59:54

标签: go exec

import (
    "fmt"
    "os/exec"
    "bytes"
)

func main() {
    cmd :="/root/hi.py > /root/1.log"

    out,err:= exec.Command("python","-c",cmd).Output()
    fmt.Printf("Out: %s ", string(out))
    fmt.Printf("Err: %s ", err.Error())

}

错误:没有此类文件错误:/root/hi.py> /root/1.log

//hi.py 

#! /usr/bin/python

print('hello world')

1 个答案:

答案 0 :(得分:1)

文件hi.py位于何处?尝试通过参数拆分它,似乎尝试文件名/root/hi.py > /root/1.log