一次性返回结果
(command string, rootDir string)
| 70 | |
| 71 | // 一次性返回结果 |
| 72 | func (eo *execOperation) CombinedOutput(command string, rootDir string) (string, error) { |
| 73 | |
| 74 | var execCommand *exec.Cmd |
| 75 | switch runtime.GOOS { |
| 76 | case "windows": |
| 77 | execCommand = exec.Command("powershell", "/c", command) |
| 78 | case "darwin": |
| 79 | execCommand = exec.Command("bash", "-c", command) |
| 80 | case "linux": |
| 81 | execCommand = exec.Command("bash", "-c", command) |
| 82 | } |
| 83 | if rootDir != "" { |
| 84 | execCommand.Dir = rootDir |
| 85 | } else { |
| 86 | homeDir, _ := os.UserHomeDir() |
| 87 | if homeDir != "" { |
| 88 | execCommand.Dir = homeDir |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | bytes, err := execCommand.CombinedOutput() |
| 93 | |
| 94 | output := strings.TrimSpace(string(bytes)) |
| 95 | SmartIDELog.Debug(fmt.Sprintf("local combine (%v) exec -> %v >>\n%v", runtime.GOOS, command, output)) |
| 96 | |
| 97 | return output, err |
| 98 | } |
no test coverage detected