20 Star 165 Fork 27

qiqi/orange

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
cmd.go 540 Bytes
一键复制 编辑 原始数据 按行查看 历史
package utils
import (
"bytes"
"fmt"
"os/exec"
"runtime"
)
// ExecShell执行shell命令
func ExecShell(shell string) (stdout string, stderr string) {
var cmd *exec.Cmd
if runtime.GOOS == "windows" {
cmd = exec.Command("cmd", "/C", shell)
} else {
cmd = exec.Command("/bin/bash", "-c", shell)
}
var out bytes.Buffer
var stderrBuf bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderrBuf
err := cmd.Run()
if err != nil {
fmt.Println("shell exec have an error", "err", err)
}
return out.String(), stderrBuf.String()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/zhucheer/orange.git
git@gitee.com:zhucheer/orange.git
zhucheer
orange
orange
v0.2.26

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385