How to execute a simple Windows command in Golang?

后端 未结 6 1962
执念已碎
执念已碎 2020-12-08 10:06

How to run a simple Windows command?

This command:

exec.Command(\"del\", \"c:\\\\aaa.txt\")

.. outputs th

6条回答
  •  暖寄归人
    2020-12-08 10:57

    In case you need the output of cmd:

    if c, err := exec.Command("cmd","/c","del","a.txt").CombinedOutput(); err != nil {
            log.Fatal(err)
        } else {
            fmt.Printf("%s\n", c)
        }
    

提交回复
热议问题