set windows PATH environment variable at runtime in Java

后端 未结 4 1712
广开言路
广开言路 2020-12-11 05:58

I have a java program that fires off an executable using the Runtime.exec() method. I\'m using the variant that takes in a set of command line params as one argument, and so

4条回答
  •  甜味超标
    2020-12-11 06:21

    If "PATH=C:\some\path" appears in your source code, it would be incorrect as it would be trying to escape the 's' and 'p' in that string, you'd use "PATH=C:\\some\\path" instead (escaping the slashes). Also, you don't want to pass it in as a string directly, but as an array of strings (likely with that as the only string in it).

提交回复
热议问题