执行来自Golang的web2exe时,给我返回了’exit status 2’。

huangapple go评论81阅读模式
英文:

Executing web2exe from Golang is giving me 'exit status 2'

问题

我正在尝试使用以下代码,使用CMD的web2exe命令将一个包含HTML文件的文件夹打包成一个可执行文件。

cmd := exec.Command("web2exe-win.exe", "html-folder --main index.html --export- to windows-x32 --output-dir")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
    fmt.Println(err)
}
fmt.Println(out)

请注意,这是一个示例代码,你需要将web2exe-win.exe替换为实际的可执行文件名,并根据你的需求修改命令行参数。

英文:

Im trying the following, to use go to bundle a folder of html files using the CMD web2exe.

cmd := exec.Command("web2exe-win.exe", "html-folder --main index.html --export- to windows-x32 --output-dir")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
	fmt.Println(err)
}
fmt.Println(out)

答案1

得分: 2

当一个程序以非零值退出时,意味着它无法成功运行,通常会将错误消息写入 STDERR(或 STDOUT)。你应该以某种方式捕获或打印输出流,以便检查其中的错误消息。例如:

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

还要注意,你的命令行参数应该是单独的数组元素(而不是现在以空格分隔的单个字符串元素):

cmd := exec.Command("web2exe-win.exe", "html-folder", "--main", "index.html", "--export-to", "windows-x32", "--output-dir")
英文:

When a program exits non-zero it means that it could not run successfully and typically it has written an error message to STDERR (or STDOUT). You should somehow capture or print the output streams so you can inspect them for error messages. For example:

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

Note also that your command line arguments should be separate array elements (instead of space separated elements in a single string as they are now):

cmd := exec.Command("web2exe-win.exe", "html-folder", "--main", "index.html", "--export-to", "windows-x32", "--output-dir")

huangapple
  • 本文由 发表于 2015年3月25日 23:56:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/29260549.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定