Golang exec.command
Jump to navigation
Jump to search
Windows
package main import( "fmt" "os/exec" "os" "log" ) func pscmd(s string){ args := []string{s} // cmd := exec.Command("powershell.exe", "ls", "-Depth", "1") cmd := exec.Command("powershell.exe", args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr err := cmd.Run() if err != nil { log.Fatalf("cmd.Run() failed with %s\n", err) } fmt.Println("======") } func main(){ pscmd("ls -Depth 1") pscmd("echo 'hi there'") }