Skip to content

Instantly share code, notes, and snippets.

@suzuki-shunsuke
Created September 27, 2024 23:10
Show Gist options
  • Save suzuki-shunsuke/6429c1f054ae06946e5ca6e923002592 to your computer and use it in GitHub Desktop.
Save suzuki-shunsuke/6429c1f054ae06946e5ca6e923002592 to your computer and use it in GitHub Desktop.
go build -o ~/bin/test-2 test-2.go
$ go run main.go
bar a b
package main
import (
"log"
"os"
"os/exec"
)
func main() {
if err := core(); err != nil {
log.Fatal(err)
}
}
func core() error {
cmd := exec.Command("test-2", "a", "b")
cmd.Args[0] = "bar"
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return err
}
return nil
}
package main
import (
"fmt"
"os"
"strings"
)
func main() {
fmt.Println(strings.Join(os.Args, " "))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment