我试图从java运行此脚本shell,但它不工作。无法从java命令行运行shell脚本
我收到此错误信息:
Process exited with an error: 1 (Exit value: 1)
有人能帮忙吗?
String pwd = "blabla";
String s_key = "0000";
String path = "C:/Files/scripts";
CommandLine commandLine = CommandLine.parse("C:\\Program Files (x86)\\Git\\bin\\git.exe");
commandLine.addArgument("fileName.sh");
commandLine.addArgument(password);
commandLine.addArgument(s_key);
DefaultExecutor defaultExecutor = new DefaultExecutor();
ByteArrayOutputStream sdtout = new ByteArrayOutputStream();
ByteArrayOutputStream sdterr = new ByteArrayOutputStream();
PumpStreamHandler streamHandler = new PumpStreamHandler(sdtout, sdterr);
defaultExecutor.setStreamHandler(streamHandler);
defaultExecutor.execute(commandLine);
这里是脚本
#!/bin/sh
pwd=$1
s_key=$2
....
echo $pwd
它用git bash的效果很好
$ ./fileName.sh blabla 0000
nkfjWmiG7dDnYUmjr6VD0A==
您是否尝试检查执行程序的Exception或stderr/stdout? https://commons.apache.org/proper/commons-exec/apidocs/org/apache/commons/exec/ExecuteStreamHandler.html –
你说的“适用于git bash”,为了执行你需要打开的shell Git Bash控制台? o您可以直接在Windows cmd控制台上执行shell? – reos
@reos是的,我使用git bash控制台,我用控制台输出更新了问题。该脚本不能在Windows cmd控制台上工作...感谢 – Prosp