go128.png

package main

import (
    "fmt"
    "os/exec"
)

func main() {
    Command("ls")
}

// 这里为了简化,我省去了stderr和其他信息
func Command(cmd string) error {
    c := exec.Command("bash", "-c", cmd)
    // 此处是windows版本
    // c := exec.Command("cmd", "/C", cmd)
    output, err := c.CombinedOutput()
    fmt.Println(string(output))
    return err
}

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code