1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
Title: Invoking the Jython Interpreter
<h3>Invoking the Jython Interpreter</h3>
<P>Jython can be invoked from the shell using the following command:</P>
<pre>
jython [options] [-jar jar | -c cmd | file | -] [args]
</pre>
Options and arguments:
<p><table border="1">
<tr><td><b>-i</b></td>
<td>inspect interactively after running script, and force prompts,
even if stdin does not appear to be a terminal
</tr><tr>
<td><b>-S</b></td>
<td>don't imply <em>import site</em> on initialization
</tr><tr>
<td><b>-D<em>prop</em>=<em>value</em></b></td>
<td>Set the jython property <em>prop</em> to <em>value</em></td>
</tr><tr>
<td><b>-jar <em>jar</em></b></td>
<td>program to run is read from the <tt>__run__.py</tt> file in
the specified <em>jar</em> file
</tr><tr>
<td><b>-c <em>cmd</em></b></td>
<td>program to run is passed in as the <em>cmd</em> string. This
option terminates the options list
</tr><tr>
<td><b><em>file</em></b></td>
<td>run <em>file</em> as the program script
</tr><tr>
<td><b>-</b></td>
<td>program is read from standard-in (default; interactive mode is
used if on a tty). This flag allows you to pipe a file into
Jython and have it be treated correctly. This would be useful
in a case like: <tt>filter file | jython -</tt>
</tr><tr>
<td><b>--help</b></td>
<td>print a usage message and exit
</tr><tr>
<td><b>--version</b></td>
<td>print Jython version number and exit
</tr><tr>
<td><b><em>args</em></b></td>
<td>arguments passed to the program in <tt>sys.argv[1:]</tt>
</tr>
</table>
<H3>Details</H3>
<P><tt>jython</tt> is a short script that invokes your local JVM,
sets the Java property <tt>install.path</tt> to an appropriate value,
and then runs the Java classfile
<tt>org.python.util.jython</tt>.</P>
<H3>Making Jython Scripts Executable</H3>
<P>To make a jython ".py" file executable on a Unix system
you can add the following line to the top of the file:
<PRE><B>#! /usr/bin/env jython</B></PRE>
<P>For this magic to work, you must have <tt>jython</tt> somewhere on your
standard PATH. You also must also make the ".py" file
executable. Typically this is done with the command:
<TT>chmod +x foo.py</TT>.
<p><I>Note: "#! <...>/jython" will probably not work to
make your script executable. This is because "jython" is
itself a script, and the #! magic requires that the file to execute is
a binary executable on most Unix variants. Using
"/usr/bin/env" will get around this problem - and make your
scripts more portable in the bargain.</I>
|