通过双击jar文件在Java GUI中运行系统命令获取空结果

时间:2019-02-11 11:23:41

标签: java command processbuilder

代码如下:

ProcessBuilder processBuilder1 = new ProcessBuilder("/usr/bin/which", "adb");

    Process process = null;
    try {
        process = processBuilder1.start();
    } catch (IOException e) {
        e.printStackTrace();
    }

    inputStreamThread inputTread = new inputStreamThread(process);
    inputTread.run();

    try {
        process.waitFor();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    process.destroy();

    ADB = inputTread.inputStreamOutput.substring(0,inputTread.inputStreamOutput.length()-1);

如果我用java -jar xxxx.jar运行它,则可以得到真实的结果,但是如果我双击jar文件,ADB结果为空,则我尝试使用新的ProcessBuilder("which", "adb");,但是没有用。

0 个答案:

没有答案