Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/fuzzyman/webapps/www.ironpython.info/includes/MagicWord.php on line 670

Warning: Invalid argument supplied for foreach() in /home/fuzzyman/webapps/www.ironpython.info/includes/MagicWord.php on line 671

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/fuzzyman/webapps/www.ironpython.info/includes/MagicWord.php on line 675

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/fuzzyman/webapps/www.ironpython.info/includes/MagicWord.php on line 670

Warning: Invalid argument supplied for foreach() in /home/fuzzyman/webapps/www.ironpython.info/includes/MagicWord.php on line 671

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/fuzzyman/webapps/www.ironpython.info/includes/MagicWord.php on line 675

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/fuzzyman/webapps/www.ironpython.info/includes/MagicWord.php on line 670

Warning: Invalid argument supplied for foreach() in /home/fuzzyman/webapps/www.ironpython.info/includes/MagicWord.php on line 671

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/fuzzyman/webapps/www.ironpython.info/includes/MagicWord.php on line 675

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/fuzzyman/webapps/www.ironpython.info/includes/MagicWord.php on line 670

Warning: Invalid argument supplied for foreach() in /home/fuzzyman/webapps/www.ironpython.info/includes/MagicWord.php on line 671

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/fuzzyman/webapps/www.ironpython.info/includes/MagicWord.php on line 675
Self-executable scripts - IronPython Cookbook

Self-executable scripts

From IronPython Cookbook

m (Small fixes and clarifications)
m (Clarified further.)
Line 20: Line 20:
</pre>
</pre>
-
Now you can just type <code>hello</code> and the script runs! The way this works is that the whole script is treated like a Windows shell (batch/command) script. The first line invokes the IronPython interpreter, which will be ideally in your <code>PATH</code>, and passes the name of the file along with all arguments. The <code>-x</code> switch tells the interpreter to skip the first line of the script and bingo! It does not trump on the first line which is illegal Python code. When the interpreter returns, <code>goto :EOF</code> will make sure that rest of the ''now-back-to-shell-script'' is skipped because the Python code make for illegal shell commands.
+
Now you can just type <code>hello</code> and the script runs! The way this works is that the whole script is treated like a Windows shell (batch/command) script. The first line invokes the IronPython interpreter, which will be ideally in your <code>PATH</code>, and passes the absolute path to the file (<code>%~f0</code>) along with all arguments (<code>%*</code>). The <code>-x</code> switch tells the interpreter to skip the first line of the script and bingo! It does not trump on the first line, which is illegal Python code. When the interpreter returns, <code>goto :EOF</code> will make sure that rest of the ''now-back-to-shell-script'' is skipped because the Python code makes for illegal shell commands.
Both worlds are hip and happy!
Both worlds are hip and happy!

Revision as of 15:13, 28 April 2009

TOOLBOX
LANGUAGES