支持命令路径获取

This commit is contained in:
白茶清欢 2023-04-09 22:52:05 +08:00
parent 4d4b871d4d
commit bd9a753bbe
3 changed files with 20 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import (
"errors"
"os"
"os/exec"
"strings"
"time"
"git.zhangdeman.cn/zhangdeman/command/define"
@ -63,6 +64,7 @@ func Execute(workDir string, command string, param []string) *define.Result {
cmdInstance := exec.Command(command, param...)
cmdInstance.Dir = result.WorkDir
result.Output, result.Error = cmdInstance.CombinedOutput()
result.Output = []byte(strings.TrimRight(string(result.Output), `\n`))
return result
}

9
git.go
View File

@ -235,3 +235,12 @@ func (g *git) Version() (string, error) {
r := Execute(g.workDir, g.gitCmdPath, []string{"version"})
return string(r.Output), r.Error
}
// GetPath 获取命令路径
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 22:49 2023/4/9
func (g *git) GetPath() string {
return g.gitCmdPath
}

View File

@ -207,3 +207,12 @@ func (g *golang) Version() (string, error) {
result := Execute(g.workDir, g.goCmdPath, []string{"version"})
return string(result.Output), result.Error
}
// GetPath 获取命令路径
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 22:49 2023/4/9
func (g *golang) GetPath() string {
return g.goCmdPath
}