changing the working-directory of command from java

后端 未结 3 1119
失恋的感觉
失恋的感觉 2020-11-27 07:28

I need to execute a .exe file from a function in one of the packages I have in my java project. now the working directory is the root directory of the project for java but t

3条回答
  •  醉梦人生
    2020-11-27 08:10

    I goted a same problem in my project, I tryed this solutions about ProcessBuilder.directory(myDir) and the exec method from Runtime and all my trays failed..
    It's make me understanding that the Runtime have a limited privileges just for the working directory and the sub directories of it.

    So my solution is ugly but working very well.
    I create a temporary .bat file in "runtime" in the working directory.
    This file included two lines of commands:
    1. Move to needed directory (cd command).
    2. Do the command in need.
    I call the exec from Runtime with my temporarily .bat file as command.
    It's work for me very well!

提交回复
热议问题