'exec format error when trying to excute a python excutable in golang
Im trying to write a cli that execute a python file from https://github.com/timeopochin/GanTTY. When excute in terminal using
python3 ./GanTTY/main.py gantt test
it will create a new interactive gantt chart. However when i do this in my go code, like this
{
Name: "project",
Usage: "add a new project with gantt chart",
Action: func(c *cli.Context) error {
cmd := exec.Command("./GanTTY/main.py", "gantt", "test")
err:= cmd.Run()
if err != nil {
log.Fatal(err)
}
fmt.Println("opend project")
return nil
},
},
and run the go program
go run program.go add project //"add" and "project" are command and sub command
it gives me this error
2022/04/03 11:42:19 fork/exec ./GanTTY/main.py: exec format error
exit status 1
Solution 1:[1]
You need to add python3 or cmd.exe /c python3 in windows.
cmd := exec.Command("python3","GanTTY/main.py", "gantt", "test")
use cmd.Dir to set directory of python file relative to current wd
cmd := exec.Command("python3","main.py", "gantt", "test")
cmd.Dir = "GanTTY"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | retrologic |
