<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>ADM Blog &#187; py</title> <atom:link href="http://blog.another-d-mention.ro/tag/py/feed/" rel="self" type="application/rss+xml" /><link>http://blog.another-d-mention.ro</link> <description>No matter how you see things, reality changes when you reach understanding</description> <lastBuildDate>Fri, 22 Jul 2011 06:56:49 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1</generator> <item><title>How to run python code in Windows batch (bat) files</title><link>http://blog.another-d-mention.ro/programming/how-to-run-python-code-in-windows-batch-bat-files/</link> <comments>http://blog.another-d-mention.ro/programming/how-to-run-python-code-in-windows-batch-bat-files/#comments</comments> <pubDate>Wed, 23 Jun 2010 12:58:05 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Programming]]></category> <category><![CDATA[Python]]></category> <category><![CDATA[bat]]></category> <category><![CDATA[batch]]></category> <category><![CDATA[code]]></category> <category><![CDATA[py]]></category> <category><![CDATA[window]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=829</guid> <description><![CDATA[Here’s the bit of tricky batch file magic that does it: 1 2 3 @setlocal enabledelayedexpansion &#38;&#38; python -x &#34;%~f0&#34; %* &#38; exit /b !ERRORLEVEL! #start python code here print &#34;hello world&#34; The way it works is that the first line of the file does two different things. 1. starts python interpreter passing the name [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/sudoku-solver-in-python/' rel='bookmark' title='Permanent Link: Sudoku solver in python'>Sudoku solver in python</a></li><li><a
href='http://blog.another-d-mention.ro/programming/python/quick-python-script-explanation/' rel='bookmark' title='Permanent Link: Quick Python Script Explanation'>Quick Python Script Explanation</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/' rel='bookmark' title='Permanent Link: Open and Save files to Desktop without going to Server'>Open and Save files to Desktop without going to Server</a></li></ol>]]></description> <content:encoded><![CDATA[<p>Here’s the bit of tricky batch file magic that does it:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
</pre></td><td
class="code"><pre class="python" style="font-family:monospace;">@setlocal enabledelayedexpansion <span style="color: #66cc66;">&amp;&amp;</span> python -x <span style="color: #483d8b;">&quot;%~f0&quot;</span> <span style="color: #66cc66;">%*</span> <span style="color: #66cc66;">&amp;</span> exit /b <span style="color: #66cc66;">!</span>ERRORLEVEL<span style="color: #66cc66;">!</span>
<span style="color: #808080; font-style: italic;">#start python code here</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;hello world&quot;</span></pre></td></tr></table></div><p>The way it works is that the first line of the file does two different things.</p><p>1. starts python interpreter passing the name of the file in, and the -x option will tell it to skip the first line (containing .bat file code)<br
/> 2. When python finishes the script exits.</p><p>This nifty trick makes it much nicer for writing admin scripts with python on Windows.</p><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/sudoku-solver-in-python/' rel='bookmark' title='Permanent Link: Sudoku solver in python'>Sudoku solver in python</a></li><li><a
href='http://blog.another-d-mention.ro/programming/python/quick-python-script-explanation/' rel='bookmark' title='Permanent Link: Quick Python Script Explanation'>Quick Python Script Explanation</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/' rel='bookmark' title='Permanent Link: Open and Save files to Desktop without going to Server'>Open and Save files to Desktop without going to Server</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/how-to-run-python-code-in-windows-batch-bat-files/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
