Created
August 11, 2021 09:14
-
-
Save mehmetron/6c85f5dc34a9bd2b2f1f3b291b4ade87 to your computer and use it in GitHub Desktop.
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 ( | |
"encoding/json" | |
"fmt" | |
"os" | |
"os/exec" | |
) | |
func GetCmdOutput(cmd []string) []byte { | |
command := exec.Command(cmd[0], cmd[1:]...) | |
command.Stderr = os.Stderr | |
output, err := command.Output() | |
if err != nil { | |
fmt.Println(err) | |
} | |
return output | |
} | |
func main() { | |
depList := GetCmdOutput([]string{"go", "list", "-m", "-json", "all"}) | |
fmt.Println("23 ", string(depList)) | |
dynamic := make(map[string]interface{}) | |
json.Unmarshal(depList, &dynamic) | |
fmt.Println("28 ", dynamic) | |
fmt.Printf("29 %+v\n", dynamic) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment