為了調用對話框可執行文件,最多需要3個按鈕,我創建了這個函數:func Dialog(icon string, text string, buttons ...string) int { cmd := &exec.Cmd{ Path: dialogPath, Args: []string{ dialogPath, icon, text, buttons..., }, Stdout: os.Stdout, Stdin: os.Stdin, } var waitStatus syscall.WaitStatus if err := cmd.Run(); err != nil { if exitError, ok := err.(*exec.ExitError); ok { waitStatus = exitError.Sys().(syscall.WaitStatus) return waitStatus.ExitStatus() } } return 0}問題是:這甚至無法編譯,因為我不知道如何將按鈕傳遞給Cmd。我以為拆包就能解決問題。
1 回答

蝴蝶刀刀
TA貢獻1801條經驗 獲得超8個贊
錯誤是:
syntax error: unexpected ..., expecting comma or }
這是因為這不是有效的語法:
Args: []string{
dialogPath,
icon,
text,
buttons...,
},
只能在函數調用中使用;您可以使用來解決此問題:...append()
Args: append([]string{dialogPath, icon, text}, buttons...),
- 1 回答
- 0 關注
- 114 瀏覽
添加回答
舉報
0/150
提交
取消