java.io.IOException:无法运行程序“:CreateProcess 错误=193,%1 不是有效的 Win32 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25511402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.io.IOException: Cannot run program ": CreateProcess error=193, %1 is not a valid Win32 application
提问by Doc Holiday
I'm getting the below error when trying to run a shell script from java in Eclipse.
尝试在 Eclipse 中从 java 运行 shell 脚本时出现以下错误。
I just created a text file on my local and wanted to see if it will run.
我刚刚在本地创建了一个文本文件,想看看它是否会运行。
new ProcessBuilder("C:/Users/myDir/Desktop/ss1.sh").start();
采纳答案by MrTux
You cannot run a shell script on Windows directly as it is no executable in the Windows sense (only .exe
, .com
, .cmd
and .bat
are executables).
因为它是在Windows意义(只无可执行文件无法在Windows上运行一个shell脚本直接.exe
,.com
,.cmd
并且.bat
是可执行文件)。
Call bash.exe
or sh.exe
and use your script as the first parameter.
调用bash.exe
或sh.exe
使用您的脚本作为第一个参数。
回答by Carles Roch-Cunill
Following MrTux comment I wrapped the py script that I was calling from groovy in a bat file and, voilà!, it works.
在 MrTux 评论之后,我将我从 groovy 调用的 py 脚本包装在一个 bat 文件中,瞧!,它起作用了。
Calling directly the py script from groovy
从groovy直接调用py脚本
def proc = "C:\MyDir\myScript.py param1 param2 param3".execute()
proc.waitFor()
def result = proc.in.text
def error = proc.err.text
it fails
它失败
Wrapping the py script in a bat file def proc = "C:\MyDir\myScriptWrapper.bat param1 param2 param3".execute()
将 py 脚本包装在 bat 文件中 def proc = "C:\MyDir\myScriptWrapper.bat param1 param2 param3".execute()
works
作品
Wonder why this behaviour in Windows is not better documented. And many thanks to MrTux
想知道为什么没有更好地记录 Windows 中的这种行为。非常感谢 MrTux