Created
August 21, 2020 16:12
-
-
Save kgrvamsi/36d8c6c8d4078173b44c5a019861ce2d to your computer and use it in GitHub Desktop.
Golang - Running Os level command
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"log" | |
"os/exec" | |
) | |
func main() { | |
cmd := exec.Command("program") // or whatever the program is | |
cmd.Dir = "C:/usr/bin" // or whatever directory it's in | |
out, err := cmd.Output() | |
if err != nil { | |
log.Fatal(err) | |
} else { | |
fmt.Printf("%s", out); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment