Difference between revisions of "Golang exec.command"
Jump to navigation
Jump to search
(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...") |
(No difference)
|
Revision as of 19:47, 15 November 2020
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'")
}