golang调用EXE

时间:2022-01-20 08:21:37

我是win7+go1.7+liteide,调用calc.exe

package main

import (
"os/exec"
) func main() {
datapath := "C:/Windows/System32/calc.exe"
cmd := exec.Command("cmd.exe", "/c", "start "+datapath)
cmd.Run()
}

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)
}
}

package main

import (
"fmt"
"os/exec"
) func main() {
f, err := exec.LookPath("ls")
if err != nil {
fmt.Println(err)
}
fmt.Println(f) // /bin/ls
}

package main

import (
"os/exec"
) func main() {
datapath := "C:/Windows/System32/calc.exe"
cd := exec.Command(datapath)
cd.Start()
}