Created
August 26, 2022 11:39
-
-
Save pcgeek86/54ac7bd70db636bab5f20094f62f3e4e to your computer and use it in GitHub Desktop.
Run External Command in 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
package main | |
import ( | |
"fmt" | |
"os/exec" | |
) | |
func main() { | |
// NOTE: mycmd will contain a byte array, not string output | |
mycmd, _ := exec.Command("ls", "-lGa", "/").Output() | |
// Convert mycmd byte array to string, and print to terminal | |
fmt.Println(string(mycmd)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment