I am running a script which launches a Java application. After execution the application creates a folder in the current working directory %systemdrive%/ProgramData\Microsoft\Windows\Caches\cversions.2.db
. I read on this question that the problem appears because of the variable %SystemDrive%
being undefined in the executed Java context.
The application is executed with :system("java -jar application.jar");
How do I explicitelly pass all the environment to the executed application?
Asked
Active
Viewed 549 times
0

Community
- 1
- 1
-
How do you start the application? Please show a minimal example of how you run it, and how you clean it up again. – simbabque Mar 20 '17 at 10:23
-
4I don't understand the question. As far as perl is concerned, there is only one set of environment variables; there is no distinction between "user" and "system". You can provide whatever environment variables you want. The default behavior is to inherit everything. – melpomene Mar 20 '17 at 10:30
-
If the java program runs as a child of the Perl program, a whitelist of allowed environment variables together with a `local %ENV` and some cleanup should work fine. But we really have to get some more details. – simbabque Mar 20 '17 at 10:33
-
@simbabque I need to update the whole question because I found that the problem doesn't come from those configuration files. The problem is that the variable `%systemdrive%` is not known in the executed Java context. – Mar 20 '17 at 12:04
-
@melpomene updated, sorry about the confusion – Mar 20 '17 at 12:12
1 Answers
3
If you are using the string %systemdrive%\ProgramData\Microsoft\Windows\Caches
to create the folder then it isn't going to work. Only the command shell will expand environment variables in a command, and Perl or Java will need to explicitly expand the value. In Perl you would use
$ENV{SYSTEMDRIVE} . '\ProgramData\Microsoft\Windows\Caches'
In Java you want
System.getenv("SYSTEMDRIVE") + . "\\ProgramData\\Microsoft\\Windows\\Caches"

Borodin
- 126,100
- 9
- 70
- 144
-
The application doesn't use it explicitlly/directly. I guess some subcomponent creates this folder ... – Mar 20 '17 at 13:04