The project
The project is a large C# project which is used for test-automation. For this purpose i’ve to use a java-tool which is the tool which saves all results into a file which can be loaded into a test-environment.
The interface
I got a DLL from the vendor of the test-environment which is build in C++, this dll loads the java environment and loads the jar files.
Current situation
The java environment is loaded with success, its configured with environment-variables set in C# with this method:
String java = GetJavaInstallationPath();
Environment.SetEnvironmentVariable("PATH", String.Format("{0};{1}", Environment.GetEnvironmentVariable("PATH"), Path.Combine(java, @"bin\client")), EnvironmentVariableTarget.Process);
After this i set the path to the java classes using this code:
Environment.SetEnvironmentVariable("ITEPCLASSPATH",
String.Format("{0};{1}",
Path.Combine(iTepPath, "itep.jar"),
Path.Combine(iTepPath, "libs\\itorx.jar")), EnvironmentVariableTarget.Process);
Which actually should work, it shows the correct value when using Environment.GetEnvironmentVariable("ITEPCLASSPATH") but the C++-DLL tells me that it isn’t working.
When setting the class path by using a external bat-file it works. Some more facts:
- The application is started by the bat file
- The path is copied from my generated path of the dll
- I don’t comment anything out, so the path is still set by C#
It seems that java is not accessing the env.-variable i set in C# but recognizes that i set it in the bat file.
I really need to set the variable via C#, how do i archive this?
It is not explicitly written in Microsoft System.Environment documentation but the target value
Processseems to limit scope to the current process only. By default, the CreateProcess method inherits current process environment for the child process. Maybe the parameters used there breaks this default behavior.So I propose you test first with
EnvironmentVariableTarget.UserinSetEnvironmentVariableto see if it works better.By the way, I think you will have to diagnose further environment variable and create process operations with tool like Process Monitor.