Golang exec.command

From UVOO Tech Wiki
Revision as of 19:47, 15 November 2020 by Busk (talk | contribs) (Created page with "Windows ``` package main import( "fmt" "os/exec" "os" "log" ) func pscmd(s string){ args := []string{s} // cmd := exec.Command("powershell.exe", "ls", "-Depth", "1...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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'")

}