Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(windows/exec): Spawn powershell to run Windows commands #179

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions otelcli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/exec"
"runtime"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -61,8 +62,17 @@ func doExec(cmd *cobra.Command, args []string) {
Value: attribute.StringValue(commandString),
})

// should this also work on Windows? for now, assume not
child := exec.Command("/bin/sh", "-c", commandString)
// use cmd.exe to launch PowerShell on Windows
var shell string
if runtime.GOOS == "windows" {
shell = "cmd.exe"
commandString = "/C powershell " + commandString
} else {
shell = "/bin/sh"
}

child := exec.Command(shell, "-c", commandString)

// attach all stdio to the parent's handles
child.Stdin = os.Stdin
child.Stdout = os.Stdout
Expand Down