feat:LocalFilesystemWithShell.execute uses cmd /c to support Windows#1759
feat:LocalFilesystemWithShell.execute uses cmd /c to support Windows#1759jinkunaier wants to merge 1 commit into
Conversation
…script execution.
|
jinkun seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR adds Windows support to LocalFilesystemWithShell.execute() by detecting the OS and using cmd /c instead of sh -c on Windows. The approach is correct and the change is small and focused. However, there is an inconsistency with the existing ShellCommandTool.java which uses "cmd.exe" (not "cmd") for the Windows shell, and the code structure could be slightly tightened to reduce duplication.
|
|
||
| if (osName.contains("win")) { | ||
| pb = | ||
| new ProcessBuilder("cmd", "/c", command) |
There was a problem hiding this comment.
[nit] Use "cmd.exe" instead of "cmd" for consistency with the existing Windows shell invocation in ShellCommandTool.java (line 559). While "cmd" works on Windows via PATHEXT resolution, using the explicit executableable name "cmd.exe" aligns with the project's established pattern and avoids any edge-case ambiguity.
new ProcessBuilder("cmd.exe", "/c", command)|
|
||
| String osName = System.getProperty("os.name").toLowerCase(); | ||
|
|
||
| ProcessBuilder pb = null; |
There was a problem hiding this comment.
[nit] ProcessBuilder pb = null; followed by two branches that both assign pb is unnecessary. Consider using a ternary to select the shell command list and constructing the ProcessBuilder once, which eliminates the null initialization and avoids duplicating .directory() and .redirectErrorStream(false):
List<String> shellCmd = osName.contains("win")
? List.of("cmd.exe", "/c", command)
: List.of("sh", "-c", command);
ProcessBuilder pb = new ProcessBuilder(shellCmd)
.directory(workDir.toFile())
.redirectErrorStream(false);Note: ShellCommandTool.java uses the same if/else pattern, so keeping the current style is also acceptable for consistency.
| .directory(workDir.toFile()) | ||
| .redirectErrorStream(false); | ||
|
|
||
| String osName = System.getProperty("os.name").toLowerCase(); |
There was a problem hiding this comment.
[nit] System.getProperty("os.name") is a JVM startup property that never changes during the process lifetime. Computing it on every execute() call is a minor inefficiency. Consider extracting it to a static final field:
private static final boolean IS_WINDOWS =
System.getProperty("os.name").toLowerCase().contains("win");That said, ShellCommandTool.java uses the same per-call approach, so this is not blocking — just a small improvement opportunity.
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR adds Windows support to LocalFilesystemWithShell.execute() by detecting the OS and using cmd /c instead of sh -c on Windows. The approach is correct and the change is small and focused. However, there is an inconsistency with the existing ShellCommandTool.java which uses "cmd.exe" (not "cmd") for the Windows shell, and the code structure could be slightly tightened to reduce duplication.
|
|
||
| if (osName.contains("win")) { | ||
| pb = | ||
| new ProcessBuilder("cmd", "/c", command) |
There was a problem hiding this comment.
[nit] Use "cmd.exe" instead of "cmd" for consistency with the existing Windows shell invocation in ShellCommandTool.java (line 559). While "cmd" works on Windows via PATHEXT resolution, using the explicit executableable name "cmd.exe" aligns with the project's established pattern and avoids any edge-case ambiguity.
new ProcessBuilder("cmd.exe", "/c", command)|
|
||
| String osName = System.getProperty("os.name").toLowerCase(); | ||
|
|
||
| ProcessBuilder pb = null; |
There was a problem hiding this comment.
[nit] ProcessBuilder pb = null; followed by two branches that both assign pb is unnecessary. Consider using a ternary to select the shell command list and constructing the ProcessBuilder once, which eliminates the null initialization and avoids duplicating .directory() and .redirectErrorStream(false):
List<String> shellCmd = osName.contains("win")
? List.of("cmd.exe", "/c", command)
: List.of("sh", "-c", command);
ProcessBuilder pb = new ProcessBuilder(shellCmd)
.directory(workDir.toFile())
.redirectErrorStream(false);Note: ShellCommandTool.java uses the same if/else pattern, so keeping the current style is also acceptable for consistency.
| .directory(workDir.toFile()) | ||
| .redirectErrorStream(false); | ||
|
|
||
| String osName = System.getProperty("os.name").toLowerCase(); |
There was a problem hiding this comment.
[nit] System.getProperty("os.name") is a JVM startup property that never changes during the process lifetime. Computing it on every execute() call is a minor inefficiency. Consider extracting it to a static final field:
private static final boolean IS_WINDOWS =
System.getProperty("os.name").toLowerCase().contains("win");That said, ShellCommandTool.java uses the same per-call approach, so this is not blocking — just a small improvement opportunity.
AgentScope-Java 2.x
Description
在LocalFilesystemWithShell execute方法中判断操作系统,通过 cmd /c 方式,支持在windows系统中执行脚本命令。