agentscope-ai / agentscope-ai/agentscope-java

[Bug]:Command Execution Fails on Windows with "Cannot run program 'sh'" Error

Đang mở
#1,396 7 bình luận 0 reaction 1 người được giao Được @wlgusqkr nhận Xem trên GitHub
area/harness bug good first issue help wanted
Ngôn ngữ chính
Java
Star
5.6k
Fork
1.3k
Merge trung bình
4 ngày 12 giờ
Pull request đã merge (30 ngày)
77

Mô tả

**Description**
When attempting to execute Shell commands via `LocalFilesystemWithShell` on Windows, the following exception occurs:

```
io.agentscope.harness.agent.filesystem.local.LocalFilesystemWithShell -- Command execution failed: Cannot run program "sh" (in directory "E:\agentscope\workspace\3846161173172182283"): CreateProcess error=2, 系统找不到指定的文件。
java.io.IOException: Cannot run program "sh" (in directory "E:\agentscope\workspace\3846161173172182283"): CreateProcess error=2, 系统找不到指定的文件。
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
...
```

The error occurs because Windows does not have the `sh` (Unix Shell) command available by default, causing the `CreateProcess` call to fail.

**Steps to Reproduce**
1. Run the relevant code on a Windows system.
2. Invoke `LocalFilesystemWithShell.execute()` or use `ShellExecuteTool` to run a Shell command.
3. Observe the console or logs for the above exception.

**Expected Behavior**
On Windows systems, the code should either:
- Automatically detect the OS and switch to an appropriate shell (e.g., `cmd` or `PowerShell`).
- Provide clear instructions to the user about how to configure the shell environment.

**Root Cause**
- The code does not check the operating system type and defaults to using the Unix `sh` command.
- There is insufficient cross-platform support for Windows environments.

**Environment Information**
- **OS**: Windows
- **Working Directory**: `E:\agentscope\workspace\3846161173172182283`
- **Related Modules**: `LocalFilesystemWithShell`, `ShellExecuteTool`

**Suggested Solutions**
1. **OS Detection**: Before executing shell commands, detect the current operating system:
- On Windows, use `cmd /c` or `PowerShell` for command execution.
- On Unix/Linux/macOS, continue using `sh`.
2. **Configurable Shell Path**: Allow users to configure a custom shell path via settings or environment variables.
3. **Documentation**: Clearly document that Windows users need to install a `sh`-compatible environment (e.g., Git Bash, Cygwin) or use alternative cross-platform command execution methods.

**Relevant Code/Logs**
See the provided stack trace.

**Additional Notes**
If this is the first time running this feature on Windows, please consider adding cross-platform compatibility notes to the documentation to help other users avoid similar issues.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.