代码拉取完成,页面将自动刷新
package sysutil
import (
"bytes"
"os/exec"
"gitee.com/ckbabby/goutil/strutil"
)
// QuickExec quick exec an simple command line
// Usage:
// QuickExec("git status")
func QuickExec(cmdLine string, workDir ...string) (string, error) {
ss := strutil.Split(cmdLine, " ")
return ExecCmd(ss[0], ss[1:], workDir...)
}
// ExecCmd an command and return output.
// Usage:
// ExecCmd("ls", []string{"-al"})
func ExecCmd(binName string, args []string, workDir ...string) (string, error) {
// create a new Cmd instance
cmd := exec.Command(binName, args...)
if len(workDir) > 0 {
cmd.Dir = workDir[0]
}
bs, err := cmd.Output()
return string(bs), err
}
// ShellExec exec command by shell
// cmdStr eg. "ls -al"
func ShellExec(cmdStr string, shells ...string) (string, error) {
// shell := "/bin/sh"
shell := "sh"
if len(shells) > 0 {
shell = shells[0]
}
var out bytes.Buffer
cmd := exec.Command(shell, "-c", cmdStr)
cmd.Stdout = &out
if err := cmd.Run(); err != nil {
return "", err
}
return out.String(), nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。