尝试使用exec.Command(

时间:2016-01-27 01:59:15

标签: python go

func execPython(fPath, colName, srv  string) (){
fmt.Println("Inside execPython")
cmd:= "python rfsvmchurn.py"
arg0 := "-fp " + fPath
arg1 := "-srv " + srv
arg2 := "-col " + colName
if err := exec.Command(cmd, arg0, arg1, arg2).Run(); err != nil {
    fmt.Println("Python Execution Error :",err)
}

}

得到错误   Python执行错误:exec:“python rfsvmchurn.py”:$ PATH中找不到可执行文件

1 个答案:

答案 0 :(得分:1)

您的问题可能是您将标志及其参数作为单个字符串传递。你应该这样做:

func execPython(fPath, colName, srv  string) (){
    fmt.Println("Inside execPython")
    arg0 := "-fp " + fPath
    arg1 := "-srv " + srv
    arg2 := "-col " + colName
    cmd := exec.Command("python", "rfsvmchurn.py", "-fp", fPath, "-srv", srv, "-col", colName)
    if err := cmd.Run(); err != nil {
        fmt.Println("Python Execution Error :",err)
    }
}