英文:
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")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论