So basically I was making a golang program using os/exec
I have an array of some strings which I wanna pass as a Command
args := ["alacritty", "--needed", "--dlpkg"]
cmd := exec.Command("pkexec", "pacman", "-S", "--noconfirm")
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
err := cmd.Run()
I need to pass the args after the –noconfirm string but everytime I want to put the array it asks for a ...string type. Is there any way to convert a string array to ...string. Or any other method to pass the array correctly through exec.Command()
>Solution :
You can put all values in a slice by using ...
args := []string{"pacman", "-S", "--noconfirm", "alacritty", "--needed", "--dlpkg"}
cmd := exec.Command("pkexec", args...)
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
err := cmd.Run()