@@ -19,7 +19,6 @@ import (
19
19
"path/filepath"
20
20
"reflect"
21
21
"regexp"
22
- "runtime"
23
22
"sort"
24
23
"strconv"
25
24
"strings"
@@ -206,7 +205,9 @@ func (a *agent) runLoop(ctx context.Context) {
206
205
}
207
206
}
208
207
209
- var isPowershellRe = regexp .MustCompile (`^(powershell|pwsh)(\.exe)?$` )
208
+ var (
209
+ isCmdExeRe = regexp .MustCompile (`^(cmd|cmd\.exe)$` )
210
+ )
210
211
211
212
func createMetadataCommand (ctx context.Context , script string ) (* exec.Cmd , error ) {
212
213
// This is largely copied from agentssh, but for some reason the command
@@ -225,18 +226,14 @@ func createMetadataCommand(ctx context.Context, script string) (*exec.Cmd, error
225
226
if err != nil {
226
227
return nil , xerrors .Errorf ("get user shell: %w" , err )
227
228
}
229
+ shellBase := filepath .Base (shell )
228
230
229
231
var args []string
230
232
switch {
231
- case runtime .GOOS == "windows" :
232
- if isPowershellRe .MatchString (filepath .Base (shell )) {
233
- args = append (args , "-NoProfile" , "-NonInteractive" , "-Command" )
234
- } else {
235
- // Probably cmd.exe
236
- args = append (args , "/c" )
237
- }
238
-
233
+ case isCmdExeRe .MatchString (shellBase ):
234
+ args = append (args , "/c" )
239
235
default :
236
+ // -c works for powershell and sh variants.
240
237
args = append (args , "-c" )
241
238
}
242
239
args = append (args , script )
0 commit comments