The go language executes the windows command line method

  • 2020-05-26 09:20:37
  • OfStack

This example demonstrates how the go language executes the windows command line. Share with you for your reference. The details are as follows:

Execute the command line from windows in golang, e.g. del d:\ a.txt command in golang

package main
import(
    "fmt"
    "os/exec"
)
func main(){  
    c := exec.Command("cmd", "/C", "del", "D:\\a.txt")
    if err := c.Run(); err != nil {
        fmt.Println("Error: ", err)
    } 
}

I hope this article is helpful for you to design Go program.


Related articles: