pu369com

golang调用EXE

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

posted on 2016-09-26 09:36  pu369com  阅读(6093)  评论(0编辑  收藏  举报

导航