What is the environment variable concept?
In a C# program I need to call an executable. The executable will call some other executables that reside in the same folder. The executables rely on the two environment variables "PATH" and "RAYPATH" to be set correctly. I tried the following two things:
- I created a process and set the two varables in StartInfo. The
variables exist already but are missing the needed information.
- I tried to set the variables with
System.Environment.SetEnvironmentVariable().
When I run the process the system can't find the executable ("executeable1"). I tried to set StartInfo.FileName to the full path of "executeable1" - however then the EXE files called form within "executeable1" are not found...
How do I deal with this?
string pathvar = System.Environment.GetEnvironmentVariable("PATH");
System.Environment.SetEnvironmentVariable("PATH", pathvar + @";C:UD_inDAYSIMin_windows;C:UD_inRadiancein;C:UD_inDAYSIM;");
System.Environment.SetEnvironmentVariable("RAYPATH", @"C:UD_inDAYSIMlib;C:UD_inRadiancelib");
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.WorkingDirectory = @"C:UD_inDAYSIMin_windows";
//string pathvar = p.StartInfo.EnvironmentVariables["PATH"];
//p.StartInfo.EnvironmentVariables["PATH"] = pathvar + @";C:UD_inDAYSIMin_windows;C:UD_inRadiancein;C:UD_inDAYSIM;";
//p.StartInfo.EnvironmentVariables["RAYPATH"] = @"C:UD_inDAYSIMlib;C:UD_inRadiancelib";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = "executeable1";
p.StartInfo.Arguments = arg1 + " " + arg2;
p.Start();
p.WaitForExit();
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…