buildNativeCommand constructs a command to run in native Windows environment.
(displayCmd *string)
| 92 | |
| 93 | // buildNativeCommand constructs a command to run in native Windows environment. |
| 94 | func (e *executor) buildNativeCommand(displayCmd *string) *exec.Cmd { |
| 95 | *displayCmd = e.command |
| 96 | if len(e.args) > 0 { |
| 97 | *displayCmd += " " + strings.Join(e.args, " ") |
| 98 | } |
| 99 | |
| 100 | var cmd *exec.Cmd |
| 101 | |
| 102 | if len(e.args) == 0 { |
| 103 | // Command without arguments: wrap in cmd.exe /c for shell features |
| 104 | cmd = exec.Command("cmd") |
| 105 | cmd.SysProcAttr = &syscall.SysProcAttr{ |
| 106 | CmdLine: fmt.Sprintf(`/c %s`, e.command), |
| 107 | HideWindow: true, // Hide console window for native commands |
| 108 | } |
| 109 | } else { |
| 110 | // Command with arguments: direct execution (safer, no shell parsing) |
| 111 | cmd = exec.Command(e.command, e.args...) |
| 112 | } |
| 113 | |
| 114 | cmd.Env = os.Environ() |
| 115 | return cmd |
| 116 | } |