首页 > 解决方案 > Golang ...字符串类型arg函数

问题描述

为什么我不能将 args 放入函数中

func ex(c string,ex ...string) { exec.Command(c,ex) }

得到错误cannot use args (type []string) as type string。为什么?

标签: go

解决方案


您可以ex...在语句中使用:exec.Command(c,ex...)而不仅仅是ex

下面作为一个例子:

func ex(c string,ex ...string) { exec.Command(c,ex...) }

推荐阅读