agentscope-ai / agentscope-ai/agentscope-java

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

Open
#1,396 7 comments 0 reactions 1 assignee Claimed by @wlgusqkr View on GitHub
area/harness bug good first issue help wanted
Dominant language
Java
Stars
5.6k
Forks
1.3k
Avg merge
4d 12h
Merged PRs (30d)
77

Description

**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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.