ProcessBuilder can't find file?!

前端 未结 2 797
名媛妹妹
名媛妹妹 2020-12-19 01:44

Another question in quick succession but this has to be a really obvious error that I am not seeing. I\'ve written some code to run a batch file below but I\'m getting an er

2条回答
  •  别那么骄傲
    2020-12-19 02:16

    I'm running Linux, but the same error occurs when I run your code (modified to run a .sh rather than .bat).

    Try:

    ProcessBuilder pb = new ProcessBuilder("c:\\adb.bat");
    

    Apparently using ProcessBuilder.directory doesn't affect the working directory (for the purposes of discovering the executable) that was chosen when the builder was constructed (at least, that's what seems to happen. The docs say it will change the working directory, so I guess input/output files might be relative to that?)

    I'm not sure what it's actually doing internally, but providing the path to the executable in the constructor fixed the problem.

    This post talks about the problem and this solution, but also raises whether environment variables have to be set, of which "path"-like variables might be useful to help ProcessBuilder discover an executable.

提交回复
热议问题