Skip to content

Commit

Permalink
调整格式
Browse files Browse the repository at this point in the history
  • Loading branch information
123123123123123123123 committed Jul 11, 2024
1 parent 00a2e63 commit 59f19ba
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions exec/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// return:exit code
func RunShellCommand(command string, environment map[string]string, workingDirectory string, outputCmd bool) (int, []string) {
receiveOutput := make(chan string, 1000)
result := RunShellContext(context.Background(), command, receiveOutput, environment, workingDirectory, outputCmd)
result := runCmdContext(context.Background(), "bash", []string{"-c", command}, receiveOutput, environment, workingDirectory, outputCmd)
return result, collections.NewListFromChan(receiveOutput).ToArray()
}

Expand All @@ -31,7 +31,7 @@ func RunShellCommand(command string, environment map[string]string, workingDirec
// workingDirectory:当前工作目录位置
// return:exit code
func RunShell(command string, receiveOutput chan string, environment map[string]string, workingDirectory string, outputCmd bool) int {
return RunShellContext(context.Background(), command, receiveOutput, environment, workingDirectory, outputCmd)
return runCmdContext(context.Background(), "bash", []string{"-c", command}, receiveOutput, environment, workingDirectory, outputCmd)
}

// RunShellContext 执行shell命令
Expand All @@ -41,10 +41,20 @@ func RunShell(command string, receiveOutput chan string, environment map[string]
// workingDirectory:当前工作目录位置
// return:exit code
func RunShellContext(ctx context.Context, command string, receiveOutput chan string, environment map[string]string, workingDirectory string, outputCmd bool) int {
return runCmdContext(ctx, "bash", []string{"-c", command}, receiveOutput, environment, workingDirectory, outputCmd)
}

// RunShellContext 执行shell命令
// command:要执行的命令
// receiveOutput:输出流
// environment:环境变量
// workingDirectory:当前工作目录位置
// return:exit code
func runCmdContext(ctx context.Context, command string, args []string, receiveOutput chan string, environment map[string]string, workingDirectory string, outputCmd bool) int {
if outputCmd {
receiveOutput <- command
}
cmd := exec.CommandContext(ctx, "bash", "-c", command)
cmd := exec.CommandContext(ctx, command, args...)
cmd.Dir = workingDirectory
// 如果设置了环境变量,则追回进来
if environment != nil {
Expand Down

0 comments on commit 59f19ba

Please sign in to comment.