How do I run a batch file from my Java Application?

后端 未结 11 1675
情书的邮戳
情书的邮戳 2020-11-22 00:42

In my Java application, I want to run a batch file that calls \"scons -Q implicit-deps-changed build\\file_load_type export\\file_load_type\"

It seems t

11条回答
  •  囚心锁ツ
    2020-11-22 01:08

    The executable used to run batch scripts is cmd.exe which uses the /c flag to specify the name of the batch file to run:

    Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c", "build.bat"});
    

    Theoretically you should also be able to run Scons in this manner, though I haven't tested this:

    Runtime.getRuntime().exec(new String[]{"scons", "-Q", "implicit-deps-changed", "build\file_load_type", "export\file_load_type"});
    

    EDIT: Amara, you say that this isn't working. The error you listed is the error you'd get when running Java from a Cygwin terminal on a Windows box; is this what you're doing? The problem with that is that Windows and Cygwin have different paths, so the Windows version of Java won't find the scons executable on your Cygwin path. I can explain further if this turns out to be your problem.

提交回复
热议问题