无法发送PARAMATERS从Java bash脚本 [英] Unable to send paramaters to bash script from java
本文介绍了无法发送PARAMATERS从Java bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过Java我的Ubuntu机器上运行bash脚本。在bash脚本需要2个输入作为我传递一个数组参数
然而,这似乎并没有被路过的数组[0]和阵列的值[1]的bash脚本?
进口java.io.BufferedReader中;
进口java.io.IOException异常;
进口java.io.InputStreamReader中;
进口org.omg.CORBA.portable.InputStream;公共类readBashScript { 公共静态无效readBashScript(){
尝试{ String []数组= {YS1,R}; 。过程PROC =调用Runtime.getRuntime()EXEC(无功/网络/红/ marsh_webreset.sh /,数组);
阅读的BufferedReader =新的BufferedReader(新的InputStreamReader(
proc.getInputStream()));
尝试{
proc.waitFor();
}赶上(InterruptedException的E){
的System.out.println(e.getMessage());
}
而(read.ready()){
的System.out.println(read.readLine());
}
}赶上(IOException异常五){
的System.out.println(e.getMessage());
}
}
}
解决方案
您正在传递的参数不正确尝试下面code:
过程PROC =调用Runtime.getRuntime()。EXEC(/无功/网络/ redbutton / marsh_webreset.sh+阵列[0] ++阵列[1] + /);
I am trying to run a bash script on my Ubuntu machine through Java. The bash script takes 2 input as parameters that i am passing as an array However, it does not seem to be passing the value of array[0] and array[1] to the bash script ?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.omg.CORBA.portable.InputStream;
public class readBashScript {
public static void readBashScript() {
try {
String[] array = {"ys1","R"};
Process proc = Runtime.getRuntime().exec("var/www/red/marsh_webreset.sh /",array);
BufferedReader read = new BufferedReader(new InputStreamReader(
proc.getInputStream()));
try {
proc.waitFor();
} catch (InterruptedException e) {
System.out.println(e.getMessage());
}
while (read.ready()) {
System.out.println(read.readLine());
}
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
解决方案
You are passing the arguments incorrectly Try below code:
Process proc = Runtime.getRuntime().exec("/var/www/redbutton/marsh_webreset.sh "+array[0]+" "+ array[1]+" /");
这篇关于无法发送PARAMATERS从Java bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文