agentscope-ai / agentscope-ai/agentscope-java

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

Abierto
#1,396 7 comentarios 0 reacciones 1 asignado Reclamado por @wlgusqkr Ver en GitHub
area/harness bug good first issue help wanted
Lenguaje dominante
Java
Estrellas
5.6k
Forks
1.3k
Merge medio
4 d 12 h
PR fusionados (30 d)
77

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.