【问题标题】:Trying to run a .bat file in another directory with java尝试使用 java 在另一个目录中运行 .bat 文件
【发布时间】:2019-08-09 13:21:04
【问题描述】:

我正在尝试使用 Process Builder 运行批处理文件 批处理文件在另一个目录中

String filepath = "D:";
        String filename = "hello.bat";
        try {
            ProcessBuilder p = new ProcessBuilder();
            p.directory(new File(filepath));
            p.command("cmd.exe", "/c ", filename);
            Process process = p.start();
            process.waitFor();
            InputStream in = process.getInputStream();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            int c = -1;
            while((c = in.read()) != -1)
            {
                baos.write(c);
            }

            String response = new String(baos.toByteArray());
            System.out.println("Response From Exe : "+response);

没有抛出异常,似乎卡在了 Process process = p.start();无限期地。 此外,批处理文件本身不会被执行 这里可能是什么问题? [我也尝试过 Runtime#exec 和 Desktop#open,但无济于事]

【问题讨论】:

    标签: java processbuilder


    【解决方案1】:

    概念将类似于:Spring boot application.properties conflict when one application deploys another

    在那里我提供了相当完整的代码集。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-12
      • 1970-01-01
      • 2015-11-06
      • 2010-10-13
      • 1970-01-01
      • 2016-11-18
      • 1970-01-01
      • 2019-01-20
      相关资源
      最近更新 更多