agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Bug]:window系统下执行任何命令工具 execute 总是出错

Open liuche51 opened this issue 4 months ago • 1 comments

AgentScope-Java is an open-source project. To involve a broader community, we recommend asking your questions in English.

Describe the bug window系统下执行命令工具 execute 总是出错,任何命令都是。经过AI分析发现原来是 ShellExecuteTool 代码中没有判断当前环境是Windows还是Linux导致。就是这一行用了 Unix 单引号语法,在 Windows cmd.exe 下会报错。

Image

需要改成如下:

Image

To Reproduce window系统下执行命令工具 execute 总是出错,任何命令都是,如下图 Image

Expected behavior Windows环境下可以正常执行cmd命令

Error messages

  • stderr:文件名、目录名或卷标语法不正确

Environment (please complete the following information):

  • AgentScope-Java Version:2.0.0-RC5
  • Java Version: [e.g. 17]
  • OS: [windows]

Additional context Add any other context about the problem here.

liuche51 avatar Jul 17 '26 11:07 liuche51

This is a valid bug. On Windows, cmd.exe does not support Unix single-quote syntax for argument escaping. The ShellExecuteTool (and likely LocalFilesystemWithShell) uses Unix-style quoting which fails on Windows.

Root cause: The shell command construction does not detect the OS and always uses Unix quoting conventions.

Suggested fix:

  1. Detect the OS at runtime via System.getProperty("os.name")
  2. On Windows, use cmd.exe /c with double-quote escaping, or prefer powershell -Command which has better quoting support
  3. Alternatively, use ProcessBuilder with argument lists instead of shell string concatenation — this avoids quoting issues entirely

Note: PR #2370 partially addresses this for sandbox filesystems by replacing inline shell commands with upload/download patterns, but the core LocalFilesystemWithShell still needs OS-aware quoting for local execution.

The fix is straightforward but requires careful testing on both Windows and Unix.

oss-maintainer avatar Jul 28 '26 09:07 oss-maintainer