Can't I run file in temporary folder using subprocess?
<p>I was trying to using this code below...</p>

<pre><code>**subprocess.Popen('%USERPROFILE%\\AppData\\Local\\Temp\\AdobeARM - Copy.log').communicate()**
</code></pre>

<p>but I got an error message.
Is there anyone can help this?</p>

<p>Since there's an environment variable in the path you can add <code>shell=True</code> to force running a batch process which will evaluate env. vars:</p>

<pre><code>subprocess.Popen('"%USERPROFILE%\\AppData\\Local\\Temp\\AdobeARM - Copy.log"',shell=True).communicate()
</code></pre>

<p>Note the protection with quotes since there are spaces. You can also drop the quotes if you pass a list containing one element to <code>Popen</code>, which is cleaner:</p>

<pre><code>subprocess.Popen(['%USERPROFILE%\\AppData\\Local\\Temp\\AdobeARM - Copy.log'],shell=True).communicate()
</code></pre>

<p>alternately if you just want to activate the default editor for your logfile, there's a simpler way (which does not block the executing script, so it's slightly different):</p>

<pre><code>p = os.path.join(os.getenv('USERPROFILE'),r"AppData\Local\Temp\AdobeARM - Copy.log")
os.startfile(p)
</code></pre>

<p>Maybe it can be even simpler since that may be the temporary directory you're trying to reach:</p>

<pre><code>p = os.path.join(os.getenv('TEMP'),r"AdobeARM - Copy.log")
os.startfile(p)
</code></pre>

python subprocess