How to access environment variables set in a script later in a batch file run from same script?
<p>My code:</p>

<pre><code>file = open("crash_reports_envs.txt")
envVariables=file.read()
print(envVariables)
file.close()

os.environ['linuxwdir'] = (re.search("linuxwdir:(\S+)",envVariables).group(1))
os.environ['invertwdir']= (re.search("wdir:(\S+.*)\\n",envVariables).group(1))
</code></pre>

<p>I am setting these environment variables in the script and running a batch file <code>file1</code> from the same script, I have another <code>file1</code> in same folder where the script is. How I can use these variables in that batch file? Right now the batch file does not recognize these variables.</p>

<p>The way you use environment variables in .bat files is to surround them with %, for example %linuxwdir%.  If I understand your <code>.bat</code> file correctly, you need something like this (untested):</p>

<pre><code>cd "C:\Program Files (x86)\PuTTY" 
pscp.exe -pw "pswd" "%invertwdir%/file2" uname@execServer:%linuxwdir%/file2
</code></pre>

python windows batch-file