来自Java程序的正在运行的Shell脚本以代码255

时间:2019-04-11 16:27:38

标签: java shell cygwin

我正在cygwin终端上从Java程序运行简单的shell脚本,该脚本运行正常,但是当我传递带有2个参数的不同的shell脚本时,返回退出代码255。在没有Java的情况下,在cygwin终端上执行相同的shell脚本就可以了程序。

在cygwin终端上使用的命令: /cygdrive/c/Users/MYNAME/Documents/abcScript.sh -u“用户名” -p“密码123”

Java程序:

进程proc = Runtime.getRuntime()。exec(new String [] {“ C:\ cygwin64 \ bin \ bash.exe”,“ -c”,“ cd / bin /; abcScript.sh -u'用户名'-p'password123'“}, 新的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);


}

0 个答案:

没有答案
相关问题