I am executing an application using Java application (Runtime.get…) but now before running the application I have to set temp path.
set tmpdir=%temp%
Is it anyway I can execute above command using Java?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Running
setin a separateRuntime.exec()invocation wouldn’t help at all: it only ever affects the process that it runs in and eachexec()call produces its own process.What you need to do instead is provide the environment variable to your
Runtime.exec()call using this two or three argument variant.Better yet, scrap
Runtime.exec()and useProcessBuilderinstead. With this you can simply useenvironment().put("tmpdir", "somevalue")to set the environment variable you want (you can even get the value of%temp%from thatMap).