浏览代码

优化代码

niujiuru 3 周之前
父节点
当前提交
e1897bf245
共有 2 个文件被更改,包括 9 次插入3 次删除
  1. 1 0
      utils/shell/execute.go
  2. 8 3
      utils/shell/executor.go

+ 1 - 0
utils/shell/execute.go

@@ -40,6 +40,7 @@ type ExecuteResult struct {
 	Stdout   string `json:"stdout"`    ///////// 标准输出
 	Stderr   string `json:"stderr"`    ///////// 错误输出
 	ExitCode int    `json:"exit_code"` ///////// 退出状态码: 0表示成功, 非0表示失败
+	Cwd      string `json:"cwd"`       ///////// 当前目录
 }
 
 type limitedBuffer struct {

+ 8 - 3
utils/shell/executor.go

@@ -7,8 +7,8 @@ import (
 )
 
 type Executor struct {
-	cwd string        // 当前工作目录
-	pg  *processGroup // 当前前台进程
+	cwd string        // 当前所在目录
+	pg  *processGroup // 当前执行进程
 }
 
 func NewExecutor() *Executor {
@@ -41,7 +41,12 @@ func (e *Executor) Exec(p ExecuteParams) (*ExecuteResult, error) {
 		e.pg = nil // 命令结束
 	}()
 
-	return executeInternal(p, func(pg *processGroup) { e.pg = pg })
+	result, err := executeInternal(p, func(pg *processGroup) { e.pg = pg })
+	if result != nil {
+		result.Cwd = e.cwd
+	}
+
+	return result, err
 }
 
 func isCD(cmd string) bool {