MCPcopy Index your code
hub / github.com/TruthHun/BookStack / ExecCommand

Function ExecCommand

utils/util.go:1080–1105  ·  view source on GitHub ↗

ExecCommand 执行cmd命令操作

(name string, args []string, timeout ...time.Duration)

Source from the content-addressed store, hash-verified

1078
1079// ExecCommand 执行cmd命令操作
1080func ExecCommand(name string, args []string, timeout ...time.Duration) (out string, err error) {
1081 var (
1082 stderr, stdout bytes.Buffer
1083 expire = 30 * time.Minute
1084 )
1085
1086 if len(timeout) > 0 {
1087 expire = timeout[0]
1088 }
1089
1090 cmd := exec.Command(name, args...)
1091 cmd.Stdout = &stdout
1092 cmd.Stderr = &stderr
1093 time.AfterFunc(expire, func() {
1094 if cmd.Process != nil && cmd.Process.Pid != 0 {
1095 out = out + fmt.Sprintf("\nexecute timeout: %v seconds.", expire.Seconds())
1096 cmd.Process.Kill()
1097 }
1098 })
1099 err = cmd.Run()
1100 if err != nil {
1101 err = fmt.Errorf("%v\n%v", err.Error(), stderr.String())
1102 }
1103 out = stdout.String()
1104 return
1105}
1106
1107// SegWords 分词
1108func SegWords(sentence string, length ...int) (words []string) {

Callers 4

IsInstalledPuppetterFunction · 0.85
IsInstalledGitFunction · 0.85
IsInstalledChromeFunction · 0.85
IsInstalledCalibreFunction · 0.85

Calls 1

RunMethod · 0.80

Tested by

no test coverage detected