当试图在Golang中裁定Python时,执行格式错误

发布于 2025-01-18 13:42:45 字数 837 浏览 2 评论 0原文

我正在尝试编写一个 cli 来执行 https://github.com/timeopochin/GanTTY。当在终端中执行时,使用

python3 ./GanTTY/main.py gantt test

它将创建一个新的交互式甘特图。然而,当我在我的 go 代码中执行此操作时,像这样

{
  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
  },
},

并运行 go 程序,

go run program.go add project //"add" and "project" are command and sub command

它给了我这个错误

2022/04/03 11:42:19 fork/exec ./GanTTY/main.py: exec format error
exit status 1

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

牵你手 2025-01-25 13:42:45

您需要在Windows中添加python3cmd.exe/c python3

cmd := exec.Command("python3","GanTTY/main.py", "gantt", "test")

使用cmd.dir相对于当前WD设置Python文件的目录

cmd := exec.Command("python3","main.py", "gantt", "test")
cmd.Dir = "GanTTY"

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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文