Skip to content

Commit

Permalink
Fix shell cmd execution for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
aandrew-me committed Jun 9, 2023
1 parent d594c52 commit 8e1b249
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,24 @@ func getCommand(shellPrompt string) {
fmt.Scan(&userInput)
if userInput == "y" {
cmdArray := strings.Split(strings.TrimSpace(fullLine), " ")
cmd := exec.Command(cmdArray[0], cmdArray[1:]...)
var cmd *exec.Cmd
if runtime.GOOS == "windows" {
shellName := "cmd"

if len(os.Getenv("PSModulePath")) > 0 {
shellName = "powershell"
}
if shellName == "cmd" {
cmd = exec.Command("cmd", "/C", fullLine)

} else {
cmd = exec.Command("powershell", fullLine)
}

} else {
cmd = exec.Command(cmdArray[0], cmdArray[1:]...)

}

cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/olekukonko/ts"
)

const localVersion = "1.6.7"
const localVersion = "1.6.8"

var bold = color.New(color.Bold)
var boldBlue = color.New(color.Bold, color.FgBlue)
Expand Down

0 comments on commit 8e1b249

Please sign in to comment.