I am calling java.lang.Runtime.exec(...) but this seems to accept the command lines as an array and I want to use a single string.
How can I do the same using a single string?
I am calling java.lang.Runtime.exec(...) but this seems to accept the command lines as an array and I want to use a single string.
How can I do the same using a single string?
From the linked Javadocs:
So just pass in
null
for the second parameter, and the environment will be inhereted.If you pass
null
for the second paramter the current environment will be inherited.If you want to modify the current environment, you can build it from
System.getEnv()
like this:Update
You can check your Java path with
System.out.println(System.getenv("PATH"));
If path is ok, then try it with
Currently there is no way of calling a system command with a command line as a single string and be able to specify the current directory.
It seems that Java API is missing this basic feature :)
The workaround is to use the array version instead of string.
From the documentation:
It sounds like you want to pass
null
for that argument.