我是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()
}