Skip to content

Instantly share code, notes, and snippets.

@jeremylowery
Created January 14, 2017 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremylowery/eb6059dcadbdbbcfee8999097c5c8217 to your computer and use it in GitHub Desktop.
Save jeremylowery/eb6059dcadbdbbcfee8999097c5c8217 to your computer and use it in GitHub Desktop.
Run a subprocess and connect to it with golang
// Credit to https://coderwall.com/p/ik5xxa/run-a-subprocess-and-connect-to-it-with-golang
package main
import (
"fmt"
"os/exec"
"os"
)
func exec_command(program string, args ...string) {
cmd := exec.Command(program, args...)
cmd.Stdin = os.Stdin;
cmd.Stdout = os.Stdout;
cmd.Stderr = os.Stderr;
err := cmd.Run()
if err != nil {
fmt.Printf("%v\n", err)
}
}
func main() {
exec_command("vagrant", "ssh")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment