Content-Length: 290595 | pFad | http://github.com/opencode-ai/opencode/pull/268/commits/30fb70c94009f0c9fcef1c720e3a1279a2397ea0

72 Feature/shell improvements /w Windows support by AxDSan · Pull Request #268 · opencode-ai/opencode · GitHub
Skip to content

Feature/shell improvements /w Windows support #268

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
fix: correct PowerShell stream handling and exit codes
  • Loading branch information
AxDSan committed Jun 27, 2025
commit 30fb70c94009f0c9fcef1c720e3a1279a2397ea0
23 changes: 18 additions & 5 deletions internal/llm/tools/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,14 +572,27 @@ func generateWrappedCommand(kind ShellKind, userCommand string, stdoutFile, stde
shellQuoteWindows(kind, cwdFile),
)
case Pwsh, WindowsPowerShell:
// PowerShell syntax - simplified to avoid hanging issues
// Use direct command execution with redirection
return fmt.Sprintf("try { %s *> %s } catch { Write-Error $_.Exception.Message *> %s }; $LASTEXITCODE | Out-File -FilePath %s -Encoding utf8; pwd | Out-File -FilePath %s -Encoding utf8\n",
// PowerShell command to execute the user's command, redirect streams, and capture exit code and CWD.
// 1. Execute the user command, redirecting stdout and stderr to their respective files.
// 2. Check the success status ($?). If true, exit code is 0.
// 3. If false, check $LASTEXITCODE for native executables. If it's non-zero, use it.
// 4. Otherwise, for failed cmdlets, default to exit code 1.
// 5. Write the determined exit code to the status file.
// 6. Write the current directory path to the CWD file.
psExitCodeLogic := fmt.Sprintf(
"if ($?) { '0' } else { if ($LASTEXITCODE -ne 0) { $LASTEXITCODE } else { '1' } } | Out-File -FilePath %s -Encoding utf8",
shellQuoteWindows(kind, statusFile),
)
psCwdLogic := fmt.Sprintf(
"(Get-Location).Path | Out-File -FilePath %s -Encoding utf8",
shellQuoteWindows(kind, cwdFile),
)
return fmt.Sprintf("%s 1>%s 2>%s; %s; %s\n",
userCommand,
shellQuoteWindows(kind, stdoutFile),
shellQuoteWindows(kind, stderrFile),
shellQuoteWindows(kind, statusFile),
shellQuoteWindows(kind, cwdFile),
psExitCodeLogic,
psCwdLogic,
)
default:
// Unix bash fallback
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/opencode-ai/opencode/pull/268/commits/30fb70c94009f0c9fcef1c720e3a1279a2397ea0

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy