為了不要一遍又一遍地重復我自己,我想創建一個處理運行一些命令的函數。func runCommand(name string, arg ...string) error { cmd := exec.Command(name, arg) if err := cmd.Run(); err != nil { return err } else { return nil }}一旦我嘗試運行它,我就會收到以下錯誤:cannot use arg (type []string) as type string in argument to exec.Command我查看了 的實現,os.Command看起來函數簽名正是我提供的。在內部 a[]string應該與可變參數相同,但對于編譯器來說似乎不是。有沒有辦法將可變參數傳遞到Command?
- 1 回答
- 0 關注
- 283 瀏覽
添加回答
舉報
0/150
提交
取消