I kind of know how to do this in C, but how to do it in Go?
This is the code I'm using:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_CMN_LEN 100
int main(int argc, char *argv[])
{
char cmd[MAX_CMN_LEN] = "", **p;
if (argc < 2) /*no command specified*/
{
fprintf(stderr, "Usage: ./program_name terminal_command ...");
exit(EXIT_FAILURE);
}
else
{
strcat(cmd, argv[1]);
for (p = &argv[2]; *p; p++)
{
strcat(cmd, " ");
strcat(cmd, *p);
}
system(cmd);
}
return 0;
}
Something like this:
package main
import (
"os"
"os/exec"
)
func main() {
if len(os.Args) < 2 {
panic("Usage: ./program_name terminal_command ...")
}
cmd := exec.Command(os.Args[1], os.Args[2:]...)
cmd.Run()
}