Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Importing environment variables

Importing environment variables

Scheduled Pinned Locked Moved C#
csharphelpquestionworkspace
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    W Kleinschmit
    wrote on last edited by
    #1

    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.

    J P 2 Replies Last reply
    0
    • W W Kleinschmit

      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.

      J Offline
      J Offline
      Jon Rista
      wrote on last edited by
      #2

      Try using the System.Environment class. It has several static methods that should help solve your problem.

      W 1 Reply Last reply
      0
      • J Jon Rista

        Try using the System.Environment class. It has several static methods that should help solve your problem.

        W Offline
        W Offline
        W Kleinschmit
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • W W Kleinschmit

          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.

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Won't the BAT file run in its own process and only affect that process?

          W 1 Reply Last reply
          0
          • P PIEBALDconsult

            Won't the BAT file run in its own process and only affect that process?

            W Offline
            W Offline
            W Kleinschmit
            wrote on last edited by
            #5

            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.

            P W 2 Replies Last reply
            0
            • W W Kleinschmit

              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.

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              I wish I knew.

              W 1 Reply Last reply
              0
              • P PIEBALDconsult

                I wish I knew.

                W Offline
                W Offline
                W Kleinschmit
                wrote on last edited by
                #7

                Me too! That's why I asked ;)

                1 Reply Last reply
                0
                • W W Kleinschmit

                  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.

                  W Offline
                  W Offline
                  W Kleinschmit
                  wrote on last edited by
                  #8

                  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.

                  P 1 Reply Last reply
                  0
                  • W W Kleinschmit

                    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.

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #9

                    Then why not just read an XML document?

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups