java - 从 java 程序运行 shell 脚本正在退出,代码为 255
问题描述
我在 cygwin 终端上从 java 程序运行简单的 shell 脚本,它运行良好,但是当我传递带有 2 个参数的不同 shell 脚本时返回退出代码 255。相同的 shell 脚本在没有 java 程序的情况下在 cygwin 终端上执行得很好。
在 cygwin 终端上使用的命令:/cygdrive/c/Users/MYNAME/Documents/abcScript.sh -u "username" -p "password123"
Java程序:
进程 proc = Runtime.getRuntime().exec(new String[] {"C:\cygwin64\bin\bash.exe", "-c", "cd /bin/ ; abcScript.sh -u '用户名' -p 'password123'" }, new String[] {"PATH=/cygdrive/c/cygwin64/bin"});
StringBuilder output=new StringBuilder();
BufferedReader reader=new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line;
while((line=reader.readLine())!=null){
output.append(line+"\n");
}
int exitVal=proc.waitFor();
System.out.println(exitVal);
if(exitVal==0){
System.out.println("Success");
System.out.println(output);
System.exit(0);
}
else{
System.out.println("failed");
}
System.out.println(proc);
}
解决方案
推荐阅读
- ios - Xamarin IOS - 围绕中心点旋转 180 度的图片(UIImage)
- java - 如何在 Flowable.generate 中使 Files.lines AutoCloseable
- ruby-on-rails - 我需要 Watir 和 Ruby 的帮助
- javascript - re-arrange UI by array in React
- sql-server - 消息 209,级别 16,状态 1,第 4 行不明确的列名称“DonorID”。消息 209,级别 16,状态 1,第 1 行不明确的列名称“DonorID”
- python-3.x - BS4 Web scraper:迭代列表在追加后跳过第一个值(仅当列表通过电子邮件发送时,不打印)
- css - 2018 年 CSS 浏览器对 min() 和 max() 的支持?
- python - Python matplotlib - 将 3D 变换应用于 Poly3DCollection
- javascript - 使用 python 和烧瓶的有趣时钟流式传输文本
- javascript - 无法打印 Json 对象属性