Importing environment variables
-
Hello, I have written a C# console-application that depends on a number of environment variables. These variables are set in a *.bat file. I would like to run that file and have the variables set in my application's environment. Unfortunatly that doesn't work, a least not by using System.Diagnostics.Process. Am I missing something? Any Idea? Thanks for any help.
-
Hello, I have written a C# console-application that depends on a number of environment variables. These variables are set in a *.bat file. I would like to run that file and have the variables set in my application's environment. Unfortunatly that doesn't work, a least not by using System.Diagnostics.Process. Am I missing something? Any Idea? Thanks for any help.
-
Try using the
System.Environment
class. It has several static methods that should help solve your problem.I know System.Environment. It allows me (among other things) to set and retrieve enviroment variables. But I need to use the *.bat file because it is not under my control and I don't otherwise know the values it will set.
-
Hello, I have written a C# console-application that depends on a number of environment variables. These variables are set in a *.bat file. I would like to run that file and have the variables set in my application's environment. Unfortunatly that doesn't work, a least not by using System.Diagnostics.Process. Am I missing something? Any Idea? Thanks for any help.
Won't the BAT file run in its own process and only affect that process?
-
Won't the BAT file run in its own process and only affect that process?
Yes. That's exactly my problem. How can I either: 1.) Access the environment of that (finished!) process? -- or -- 2.) Make another process acces the environment of my process? BTW:
System.Diagnostics.ProcessStartInfo.EnvironmentVariables
is of no help here. -
Yes. That's exactly my problem. How can I either: 1.) Access the environment of that (finished!) process? -- or -- 2.) Make another process acces the environment of my process? BTW:
System.Diagnostics.ProcessStartInfo.EnvironmentVariables
is of no help here.I wish I knew.
-
I wish I knew.
Me too! That's why I asked ;)
-
Yes. That's exactly my problem. How can I either: 1.) Access the environment of that (finished!) process? -- or -- 2.) Make another process acces the environment of my process? BTW:
System.Diagnostics.ProcessStartInfo.EnvironmentVariables
is of no help here.The workaround I use now is calling something like:
cmd.exe /c "call settings.bat > nul & set"
and parse the output (of the 'set' command). UGLY! Any better solution will be more than welcome.
-
The workaround I use now is calling something like:
cmd.exe /c "call settings.bat > nul & set"
and parse the output (of the 'set' command). UGLY! Any better solution will be more than welcome.
Then why not just read an XML document?