The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Paul Clapham wrote:I'm pretty sure you can't set environment variables inside a process in any language at all. But as far as I can see there isn't any point in setting the PATH environment variable in your Java code, since the process where your application is running is never going to use it anyway. Or is it?
The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Paul Clapham wrote:Those installers will be setting the system-level environment variables, not the copies of the variables which are provided to the process. I assume that to change the former, you would have to change some registry entries or call a low-level API or something like that. The latter can't be changed by the process itself.
And as I said, there's no need for your Java class to change its PATH environment variable because it can't possibly use it anyway. It might possibly create a new process which needs a modified version of the PATH variable, but the Process class allows you to do that in a straightforward way in any case. If your specific requirement was to change some other environment variable, then it wasn't very helpful to use PATH as your example, I don't think. So perhaps you could explain your actual requirement and why you think that changing an environment variable is the way to implement that requirement?
The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Paul Clapham wrote:That depends on how you're going to be running ANT and ffmpeg. My suggestion would be to set the environment variables as the first steps in the batch script which does those things.
The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:FYI, both ProcessBuilder and Runtime.exec allow you to pass additional environment variables. The problem with Runtime.exec is that you need to provide either null or all of the existing environment variables as well. If you only provide the new ones, most of the others will be dropped. ProcessBuilder is better for that. For example:
The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
naved momin wrote:but if i do this then any time i invoke ant or ffmpeg commands i have to rewrite this steps or it will set the environment variable till my java process killed ?