3
回答
ProcessBuilder问题
滴滴云服务器,限时包月0.9元,为开发者而生>>>   


    /**
     * @param args
     * @throws Exception
     */
    @Test
    public void main2() throws Exception {
        ProcessBuilder pb = new ProcessBuilder("javac","-d","E:\\tar", "E:\\Test.java");
        pb.directory(new File("D:\\software\\green\\java\\jdk8_64\\jdk1.8.0_66"));
        File log = new File("E:\\log.txt");
        pb.redirectErrorStream(true);
        pb.redirectOutput(Redirect.appendTo(log));
        Process p = pb.start();
    }
    
    
    @Test
    public void main() throws Exception {
        ProcessBuilder pb = new ProcessBuilder("BaiduYunGuanjia.exe");
        pb.directory(new File("D:\\software\\BaiduYunGuanjia"));
        File log = new File("E:\\log.txt");
        pb.redirectErrorStream(true);
        pb.redirectOutput(Redirect.appendTo(log));
        Process p = pb.start();
    }

main2正常运行  main报错  其实文件是存在的(直接 cmd 是可以 执行的,换到java 报文件找不到 好搞笑)不知道是不是 jdk 的问题

 

 

<无标签>
举报
哎呦-又忘了
发帖于10个月前 3回/108阅

ProcessBuilder pb = new ProcessBuilder("D:\\software\\BaiduYunGuanjia\\BaiduYunGuanjia.exe");


不要轻易怀疑是库的问题, 也许某些api你理解错了 

--- 共有 1 条评论 ---
哎呦-又忘了那该怎么用喔? 我楼有补充 10个月前 回复
 @Test 
    public void mysql() throws Exception {
        //ProcessBuilder pb = new ProcessBuilder("mysql","-u","root", "-p");
        // new ProcessBuilder("mysqldump.exe",dbName,"-h"+host,"-u"+username,"-p"+password);
        ProcessBuilder pb =new ProcessBuilder("mysqldump.exe","ssh","-h127.0.0.1","-uroot","-p123");
        //pb.directory(new File("D:\\Software\\green\\mysql-5.6\\bin"));
        File log = new File("E:\\ocr\\log.txt");
        pb.redirectErrorStream(true);
        pb.redirectOutput(Redirect.appendTo(log));
        Process p = pb.start();
    }

 

环境什么的都是好的,总是报错诶

 

顶部