使用ProcessBuilder运行msys.bat [英] Running msys.bat using ProcessBuilder

查看:281
本文介绍了使用ProcessBuilder运行msys.bat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ProcessBuilder在java中运行msys.bat。当我使用我的程序运行.bat文件时,发生以下错误:找不到rxvt.exe或sh.exe二进制文件 - 中止。按任意键继续...

I am attempting to run msys.bat in java using ProcessBuilder. When I run the .bat file with my program, the following error occurred: "Cannot find the rxvt.exe or sh.exe binary -- aborting. Press any key to continue . . ."

这是代码,

    ProcessBuilder Msys = new ProcessBuilder("C:/msys/1.0/msys.bat", "/C", "find \"C:/Users/Dan G/Desktop/hello.elf\"");

    Process p = Msys.start();

    String line;
    BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
    while ((line = r.readLine()) != null) {
        System.out.println(line);
    }
    r.close();

目标是编译我的一些C项目。那里的命令只是为了测试结果,而不是我想要完成的。

The goal is to compile some C projects of mine. The command up there is just to test for a result, not what I want to accomplish.

感谢您的帮助!

推荐答案

.bat文件可以' t自己运行并在Windows命令处理器上调用。所以不要忘记在你的bat文件之前加载Windows命令处理器cmd.exe。

.bat files can't run on their own and are called on the Windows command processor. So don't forget to load the Windows command processor too, cmd.exe before your bat file.

ProcessBuilder Msys = new ProcessBuilder("cmd.exe", "C:/msys/1.0/msys.bat", 
       "/C", "find \"C:/Users/Dan G/Desktop/hello.elf\"");

编辑

请查看此有用的文章有关此过程发生的提示和陷阱:当runtime.exec时( )不会。文章中的代码有点陈旧,但这些概念在今天和当时一样密切相关。强烈推荐。

Edit
Please check out this useful article for tips and traps that occur with this process: when runtime.exec() won't. The code in the article is a bit dated, but the concepts are just as germane today as they were then. It is highly recommended.

这篇关于使用ProcessBuilder运行msys.bat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆