无法从Java向bash脚本发送参数 [英] Unable to send parameters to bash script from java

查看:40
本文介绍了无法从Java向bash脚本发送参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Java在Ubuntu计算机上运行bash脚本.bash脚本将2个输入作为我作为数组传递的参数但是,它似乎没有将array [0]和array [1]的值传递给bash脚本吗?

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]+" /");

这篇关于无法从Java向bash脚本发送参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆