Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
向ProcessBuilder-Java添加参数_Java_Eclipse_Scripting - Fatal编程技术网

向ProcessBuilder-Java添加参数

向ProcessBuilder-Java添加参数,java,eclipse,scripting,Java,Eclipse,Scripting,我想向ProcessBuilder添加参数。我有一个类似test.sh的shell脚本 echo "hello" read user read pw 我想用Process Builder调用这个脚本test.sh,将用户和pw作为参数。脚本会自动执行此操作。否则我总是必须输入用户和密码。。 用户名和密码总是一样的,这就是为什么我想自动执行此操作的原因 脚本的完整路径如下{/c/users/lia/desktop/test.sh..} 因此,当我在git bash中执行这个脚本时,它直接在桌面上

我想向ProcessBuilder添加参数。我有一个类似test.sh的shell脚本

echo "hello"
read user
read pw
我想用Process Builder调用这个脚本test.sh,将用户和pw作为参数。脚本会自动执行此操作。否则我总是必须输入用户和密码。。 用户名和密码总是一样的,这就是为什么我想自动执行此操作的原因

脚本的完整路径如下{/c/users/lia/desktop/test.sh..}

因此,当我在git bash中执行这个脚本时,它直接在桌面上使用sh test.sh,我得到了内容,并且工作正常

在我的字符串中,我有如下字符串[]cmd={sh test.sh,user,pw}

当我把它转换成一个jar文件时,我需要它作为一个jar文件,但它不起作用。收到消息“找不到文件”

当我这样做时:String[]cmd={/c/users/lia/desktop/test.sh..};它不起作用


谢谢大家。

您可以像下面给出的示例那样编写shell脚本

echo "hello"
echo "user $1"
echo "pw: $2"

现在您必须作为sh test.sh uname1 pwd1执行。在Java ProcessBuilder中使用此命令执行。

您将如何执行windows中的shell脚本.sh文件?我在git bash中执行sh test.sh,其工作正常:@rghome的可能副本可能是。。但我仍然不明白:shell脚本读取输入。您需要将其更改为使用参数,例如$1、$2等。您好,谢谢。我想添加username和pw作为参数,因为它们总是相同的。。不想总是键入它:D@Sambit除非您的答案没有回答问题,有语法错误,而且通常似乎没有任何意义。@rghome可能是sh/c/users/Lia/desktop/test.sh可能是这样,我的代码在顶部?