Skip to content

Commit b001437

Browse files
committed
Try -c all around
1 parent 62a76f4 commit b001437

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

agent/agent.go

+7-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"path/filepath"
2020
"reflect"
2121
"regexp"
22-
"runtime"
2322
"sort"
2423
"strconv"
2524
"strings"
@@ -206,7 +205,9 @@ func (a *agent) runLoop(ctx context.Context) {
206205
}
207206
}
208207

209-
var isPowershellRe = regexp.MustCompile(`^(powershell|pwsh)(\.exe)?$`)
208+
var (
209+
isCmdExeRe = regexp.MustCompile(`^(cmd|cmd\.exe)$`)
210+
)
210211

211212
func createMetadataCommand(ctx context.Context, script string) (*exec.Cmd, error) {
212213
// 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
225226
if err != nil {
226227
return nil, xerrors.Errorf("get user shell: %w", err)
227228
}
229+
shellBase := filepath.Base(shell)
228230

229231
var args []string
230232
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")
239235
default:
236+
// -c works for powershell and sh variants.
240237
args = append(args, "-c")
241238
}
242239
args = append(args, script)

agent/agent_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ func TestAgent_Metadata(t *testing.T) {
10291029

10301030
collectedAt1 := gotMd["greeting"].CollectedAt
10311031
if !assert.Equal(t, "hello", strings.TrimSpace(gotMd["greeting"].Value)) {
1032-
t.Logf("got: %+v", gotMd)
1032+
t.Errorf("got: %+v", gotMd)
10331033
}
10341034

10351035
if !assert.Eventually(t, func() bool {

0 commit comments

Comments
 (0)