GO: Execute Shell commands

Um Shell Kommandos auszuführen und den Output zu bekommen verwendet man das „os/exec“ Package.

package main

import (
	"fmt"
	"os/exec"
)

func main() {
	app := "uname"
	arg0 := "-a"

	cmd := exec.Command(app, arg0)
	stdout, err := cmd.Output()

	if err != nil {
		fmt.Println(err.Error())
		return
	}

	fmt.Println(string(stdout))
}

Schreibe einen Kommentar

This site uses Akismet to reduce spam. Learn how your comment data is processed.