title: programmatically create environment variables using batch script
body: <p>On application start, I want to store certain application configuration keys (ex: directory path, database connection string) as an environment variable by running a <code>batch script</code>. I have tried this by writing Powershell script as guided in this article <a href="https://cmatskas.com/application-configuration-settings-across-multiple-environments/" rel="nofollow noreferrer">here</a>, which works absolutely fine. I tried the same using the <code>batch</code> file like below but it doesn't seem to be working.</p>
  
  <p>Below is sample of <code>.bat</code> file which I am trying to load/configure at the application start.</p>
  
  <p>EDIT: Correcting <code>.bat</code> the script as suggested by <em>Compo</em> in the comment section below.</p>
  
  <pre><code>@echo off
  SET "LOG=api.log"
  SET "DATABASE_URL=host=xyz.rs.aws.com dbname=somename user=someuser password=somepassword sslmode=enable"
  SET "LISTEN_PROTOCOL=http"
  @echo on
  </code></pre>
  
  <p>Below is sample code used to run the sample.bat file and fetch the value,</p>
  
  <pre><code>    string batFilePath = string.Format(@"D:\sample.bat");
      Process proc = new Process();
      proc.StartInfo.WorkingDirectory = batFilePath ;
      proc.StartInfo.CreateNoWindow = true;
      proc.Start()
      proc.WaitForExit();
  
     // fetch the value set by batch file
     var data = Environment.GetEnvironmentVariable("LOG"); // returns null here
  </code></pre>
  
  <p>However, I also wanted to know, Is it possible to create and store environment variables at the application process level? i.e. I should be able to use these environment variables only within the application level, not at the system/user level.</p>