Created
January 14, 2017 01:26
-
-
Save jeremylowery/eb6059dcadbdbbcfee8999097c5c8217 to your computer and use it in GitHub Desktop.
Run a subprocess and connect to it with golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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