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中找不到可执行文件

最佳答案

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

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)
    }
}

关于python - 尝试使用exec.Command在golang中执行python(,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35027519/

10-12 13:40