Skip to content

fix(tools): suppress Windows AutoRun stderr in shell commands#1556

Merged
xieyxclack merged 2 commits intoagentscope-ai:mainfrom
mvanhorn:osc/1545-windows-shell-stderr-autorun
Mar 16, 2026
Merged

fix(tools): suppress Windows AutoRun stderr in shell commands#1556
xieyxclack merged 2 commits intoagentscope-ai:mainfrom
mvanhorn:osc/1545-windows-shell-stderr-autorun

Conversation

@mvanhorn
Copy link
Contributor

Summary

On Windows, every execute_shell_command call produces spurious "The system cannot find the path specified." stderr output, even when the command succeeds with returncode 0. This happens because subprocess.Popen(shell=True) invokes cmd.exe, which runs AutoRun scripts from the registry (HKCU\Software\Microsoft\Command Processor\AutoRun). If AutoRun references a nonexistent path, stderr gets polluted.

Changes

  • shell.py: Replace shell=True with an explicit ["cmd", "/D", "/S", "/C", cmd] invocation. The /D flag disables AutoRun processing (Microsoft docs). The /S flag ensures the inner command string is passed through unchanged, preserving pipes, redirects, and shell builtins.

This function is only called on Windows (sys.platform == "win32" gate at line 166), so non-Windows platforms are unaffected.

Testing

The fix follows standard Windows practice for subprocess invocation. The existing creationflags=subprocess.CREATE_NEW_PROCESS_GROUP handling is preserved. Commands with pipes (echo a | sort), redirects (echo a > file), and shell builtins (dir, type) continue to work because cmd /S /C processes them.

Fixes #1545

This contribution was developed with AI assistance (Claude Code).

On Windows, subprocess.Popen with shell=True invokes cmd.exe which
runs AutoRun scripts from the registry. If AutoRun references a
nonexistent path, stderr gets "The system cannot find the path
specified." even when the command succeeds. This switches to an
explicit cmd /D /S /C invocation to disable AutoRun processing,
preventing spurious stderr output.

Fixes agentscope-ai#1545

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added the first-time-contributor PR created by a first time contributor label Mar 16, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue on Windows where execute_shell_command calls would produce unnecessary stderr output due to cmd.exe attempting to run nonexistent AutoRun scripts. The solution involves explicitly invoking cmd.exe with flags to disable AutoRun and correctly parse the command, thereby cleaning up the stderr output without affecting functionality or non-Windows platforms.

Highlights

  • Windows stderr suppression: Modified execute_shell_command to prevent spurious "The system cannot find the path specified." stderr output on Windows by disabling cmd.exe AutoRun scripts.
  • Subprocess invocation on Windows: Replaced shell=True with an explicit ["cmd", "/D", "/S", "/C", cmd] invocation for Windows, ensuring AutoRun is disabled (/D) and command parsing is preserved (/S).

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/copaw/agents/tools/shell.py
    • Modified _execute_subprocess_sync to explicitly construct the command array for subprocess.Popen on Windows.
    • Switched shell=True to shell=False and passed the wrapped command list.
    • Added comments explaining the purpose of the /D and /S flags for cmd.exe.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively resolves an issue with spurious stderr output on Windows during shell command execution by disabling AutoRun scripts. The approach of explicitly calling cmd.exe with the /D flag is a clean and targeted fix. The change is correctly scoped to Windows environments. I have one suggestion to improve the accuracy of a code comment for better long-term maintainability.

Copy link
Member

@xieyxclack xieyxclack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@xieyxclack xieyxclack temporarily deployed to maintainer-approved March 16, 2026 09:01 — with GitHub Actions Inactive
@xieyxclack xieyxclack merged commit 70acceb into agentscope-ai:main Mar 16, 2026
24 checks passed
@github-actions
Copy link

Welcome to CoPaw! 🎉

Thank you @mvanhorn for your first contribution! Your PR has been merged. 🚀

We'd love to give you a shout-out in our release notes! If you're comfortable sharing, please reply to this comment with your social media handles using the format below:

discord: your_discord_handle
x: your_x_handle
xiaohongshu: your_xiaohongshu_id

Note: Only share what you're comfortable with — all fields are optional.

Thanks again for helping make CoPaw better!

@mvanhorn
Copy link
Contributor Author

github: @mvanhorn
twitter/x: @mvanhorn
discord: mvanhorn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

first-time-contributor PR created by a first time contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:Windows 平台 execute_shell_command 工具 stderr 显示"系统找不到指定的路径。"错误

3 participants