perlos2.html

来自「perl教程」· HTML 代码 · 共 1,320 行 · 第 1/5 页

HTML
1,320 行
字号
<dd>
<p>One can get different parts of EMX from, say</p>
</dd>
<dd>
<pre>
  <a href="http://www.leo.org/pub/comp/os/os2/leo/gnu/emx+gcc/">http://www.leo.org/pub/comp/os/os2/leo/gnu/emx+gcc/</a>
  <a href="http://powerusersbbs.com/pub/os2/dev/">http://powerusersbbs.com/pub/os2/dev/</a>   [EMX+GCC Development]
  <a href="http://hobbes.nmsu.edu/pub/os2/dev/emx/v0.9d/">http://hobbes.nmsu.edu/pub/os2/dev/emx/v0.9d/</a></pre>
</dd>
<dd>
<p>The runtime component should have the name <em>emxrt.zip</em>.</p>
</dd>
<dd>
<p><strong>NOTE</strong>. When using <em>emx.exe</em>/<em>rsx.exe</em>, it is enough to have them on your path. One
does not need to specify them explicitly (though this</p>
</dd>
<dd>
<pre>
  emx perl_.exe -de 0</pre>
</dd>
<dd>
<p>will work as well.)</p>
</dd>
</li>
<dt><strong><a name="item_rsx">RSX</a></strong>

<dd>
<p>To run Perl on DPMI platforms one needs RSX runtime. This is
needed under DOS-inside-OS/2, Win0.3*, Win0.95 and WinNT (see 
<a href="#other_oses">Other OSes</a>). RSX would not work with VCPI
only, as EMX would, it requires DMPI.</p>
</dd>
<dd>
<p>Having RSX and the latest <em>sh.exe</em> one gets a fully functional
<strong>*nix</strong>-ish environment under DOS, say, <a href="../../lib/Pod/perlfunc.html#item_fork"><code>fork</code></a>, <code>``</code> and
pipe-<a href="../../lib/Pod/perlfunc.html#item_open"><code>open</code></a> work. In fact, MakeMaker works (for static build), so one
can have Perl development environment under DOS.</p>
</dd>
<dd>
<p>One can get RSX from, say</p>
</dd>
<dd>
<pre>
  <a href="ftp://ftp.cdrom.com/pub/os2/emx09c/contrib">ftp://ftp.cdrom.com/pub/os2/emx09c/contrib</a>
  <a href="ftp://ftp.uni-bielefeld.de/pub/systems/msdos/misc">ftp://ftp.uni-bielefeld.de/pub/systems/msdos/misc</a>
  <a href="ftp://ftp.leo.org/pub/comp/os/os2/leo/devtools/emx+gcc/contrib">ftp://ftp.leo.org/pub/comp/os/os2/leo/devtools/emx+gcc/contrib</a></pre>
</dd>
<dd>
<p>Contact the author on <code>rainer@mathematik.uni-bielefeld.de</code>.</p>
</dd>
<dd>
<p>The latest <em>sh.exe</em> with DOS hooks is available in</p>
</dd>
<dd>
<pre>
  <a href="http://www.ilyaz.org/software/os2/">http://www.ilyaz.org/software/os2/</a></pre>
</dd>
<dd>
<p>as <em>sh_dos.zip</em> or under similar names starting with <code>sh</code>, <a href="#item_pdksh"><code>pdksh</code></a> etc.</p>
</dd>
</li>
<dt><strong><a name="item_hpfs">HPFS</a></strong>

<dd>
<p>Perl does not care about file systems, but the perl library contains
many files with long names, so to install it intact one needs a file
system which supports long file names.</p>
</dd>
<dd>
<p>Note that if you do not plan to build the perl itself, it may be
possible to fool EMX to truncate file names. This is not supported,
read EMX docs to see how to do it.</p>
</dd>
</li>
<dt><strong><a name="item_pdksh">pdksh</a></strong>

<dd>
<p>To start external programs with complicated command lines (like with
pipes in between, and/or quoting of arguments), Perl uses an external
shell. With EMX port such shell should be named <em>sh.exe</em>, and located
either in the wired-in-during-compile locations (usually <em>F:/bin</em>),
or in configurable location (see <a href="#perl_sh_dir">PERL_SH_DIR</a>).</p>
</dd>
<dd>
<p>For best results use EMX pdksh. The standard binary (5.2.14 or later) runs
under DOS (with <a href="#item_rsx">RSX</a>) as well, see</p>
</dd>
<dd>
<pre>
  <a href="http://www.ilyaz.org/software/os2/">http://www.ilyaz.org/software/os2/</a></pre>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="starting_perl_programs_under_os_2__and_dos_and____">Starting Perl programs under OS/2 (and DOS and...)</a></h2>
<p>Start your Perl program <em>foo.pl</em> with arguments <code>arg1 arg2 arg3</code> the
same way as on any other platform, by</p>
<pre>
        perl foo.pl arg1 arg2 arg3</pre>
<p>If you want to specify perl options <code>-my_opts</code> to the perl itself (as
opposed to your program), use</p>
<pre>
        perl -my_opts foo.pl arg1 arg2 arg3</pre>
<p>Alternately, if you use OS/2-ish shell, like CMD or 4os2, put
the following at the start of your perl script:</p>
<pre>
        extproc perl -S -my_opts</pre>
<p>rename your program to <em>foo.cmd</em>, and start it by typing</p>
<pre>
        foo arg1 arg2 arg3</pre>
<p>Note that because of stupid OS/2 limitations the full path of the perl
script is not available when you use <code>extproc</code>, thus you are forced to
use <a href="../../lib/Pod/perlrun.html#item__2ds"><code>-S</code></a> perl switch, and your script should be on the <a href="../../lib/Pod/perlrun.html#item_path"><code>PATH</code></a>. As a plus
side, if you know a full path to your script, you may still start it
with</p>
<pre>
        perl ../../blah/foo.cmd arg1 arg2 arg3</pre>
<p>(note that the argument <code>-my_opts</code> is taken care of by the <code>extproc</code> line
in your script, see <a href="#c_extproc__on_the_first_line"><code>extproc</code> on the first line</a>).</p>
<p>To understand what the above <em>magic</em> does, read perl docs about <a href="../../lib/Pod/perlrun.html#item__2ds"><code>-S</code></a>
switch - see <a href="../../lib/Pod/perlrun.html">the perlrun manpage</a>, and cmdref about <code>extproc</code>:</p>
<pre>
        view perl <a href="../../lib/Pod/perlrun.html">perlrun</a>
        man <a href="../../lib/Pod/perlrun.html">perlrun</a>
        view cmdref extproc
        help extproc</pre>
<p>or whatever method you prefer.</p>
<p>There are also endless possibilities to use <em>executable extensions</em> of
4os2, <em>associations</em> of WPS and so on... However, if you use
*nixish shell (like <em>sh.exe</em> supplied in the binary distribution),
you need to follow the syntax specified in <a href="../../lib/Pod/perlrun.html#switches">Switches in the perlrun manpage</a>.</p>
<p>Note that <strong>-S</strong> switch supports scripts with additional extensions 
<em>.cmd</em>, <em>.btm</em>, <em>.bat</em>, <em>.pl</em> as well.</p>
<p>
</p>
<h2><a name="starting_os_2__and_dos__programs_under_perl">Starting OS/2 (and DOS) programs under Perl</a></h2>
<p>This is what <a href="../../lib/Pod/perlfunc.html#item_system"><code>system()</code></a> (see <a href="../../lib/Pod/perlfunc.html#system">system in the perlfunc manpage</a>), <code>``</code> (see
<a href="../../lib/Pod/perlop.html#i_o_operators">I/O Operators in the perlop manpage</a>), and <em>open pipe</em> (see <a href="../../lib/Pod/perlfunc.html#open">open in the perlfunc manpage</a>)
are for. (Avoid <a href="../../lib/Pod/perlfunc.html#item_exec"><code>exec()</code></a> (see <a href="../../lib/Pod/perlfunc.html#exec">exec in the perlfunc manpage</a>) unless you know what you
do).</p>
<p>Note however that to use some of these operators you need to have a
sh-syntax shell installed (see <a href="#item_pdksh">Pdksh</a>, 
<a href="#frequently_asked_questions">Frequently asked questions</a>), and perl should be able to find it
(see <a href="#perl_sh_dir">PERL_SH_DIR</a>).</p>
<p>The cases when the shell is used are:</p>
<ol>
<li>
<p>One-argument <a href="../../lib/Pod/perlfunc.html#item_system"><code>system()</code></a> (see <a href="../../lib/Pod/perlfunc.html#system">system in the perlfunc manpage</a>), <a href="../../lib/Pod/perlfunc.html#item_exec"><code>exec()</code></a> (see <a href="../../lib/Pod/perlfunc.html#exec">exec in the perlfunc manpage</a>)
with redirection or shell meta-characters;</p>
</li>
<li>
<p>Pipe-open (see <a href="../../lib/Pod/perlfunc.html#open">open in the perlfunc manpage</a>) with the command which contains redirection 
or shell meta-characters;</p>
</li>
<li>
<p>Backticks <code>``</code> (see <a href="../../lib/Pod/perlop.html#i_o_operators">I/O Operators in the perlop manpage</a>) with the command which contains
redirection or shell meta-characters;</p>
</li>
<li>
<p>If the executable called by system()/exec()/pipe-open()/<code>``</code> is a script
with the &quot;magic&quot; <code>#!</code> line or <code>extproc</code> line which specifies shell;</p>
</li>
<li>
<p>If the executable called by system()/exec()/pipe-open()/<code>``</code> is a script
without &quot;magic&quot; line, and <code>$ENV{EXECSHELL}</code> is set to shell;</p>
</li>
<li>
<p>If the executable called by system()/exec()/pipe-open()/<code>``</code> is not
found (is not this remark obsolete?);</p>
</li>
<li>
<p>For globbing (see <a href="../../lib/Pod/perlfunc.html#glob">glob in the perlfunc manpage</a>, <a href="../../lib/Pod/perlop.html#i_o_operators">I/O Operators in the perlop manpage</a>)
(obsolete? Perl uses builtin globbing nowadays...).</p>
</li>
</ol>
<p>For the sake of speed for a common case, in the above algorithms 
backslashes in the command name are not considered as shell metacharacters.</p>
<p>Perl starts scripts which begin with cookies
<code>extproc</code> or <code>#!</code> directly, without an intervention of shell.  Perl uses the
same algorithm to find the executable as <em>pdksh</em>: if the path
on <code>#!</code> line does not work, and contains <code>/</code>, then the directory
part of the executable is ignored, and the executable
is searched in <em>.</em> and on <a href="../../lib/Pod/perlrun.html#item_path"><code>PATH</code></a>.  To find arguments for these scripts
Perl uses a different algorithm than <em>pdksh</em>: up to 3 arguments are 
recognized, and trailing whitespace is stripped.</p>
<p>If a script
does not contain such a cooky, then to avoid calling <em>sh.exe</em>, Perl uses
the same algorithm as <em>pdksh</em>: if <code>$ENV{EXECSHELL}</code> is set, the
script is given as the first argument to this command, if not set, then
<code>$ENV{COMSPEC} /c</code> is used (or a hardwired guess if <code>$ENV{COMSPEC}</code> is
not set).</p>
<p>When starting scripts directly, Perl uses exactly the same algorithm as for 
the search of script given by <strong>-S</strong> command-line option: it will look in
the current directory, then on components of <code>$ENV{PATH}</code> using the 
following order of appended extensions: no extension, <em>.cmd</em>, <em>.btm</em>, 
<em>.bat</em>, <em>.pl</em>.</p>
<p>Note that Perl will start to look for scripts only if OS/2 cannot start the
specified application, thus <code>system 'blah'</code> will not look for a script if 
there is an executable file <em>blah.exe</em> <em>anywhere</em> on <a href="../../lib/Pod/perlrun.html#item_path"><code>PATH</code></a>.  In
other words, <a href="../../lib/Pod/perlrun.html#item_path"><code>PATH</code></a> is essentially searched twice: once by the OS for
an executable, then by Perl for scripts.</p>
<p>Note also that executable files on OS/2 can have an arbitrary extension, 
but <em>.exe</em> will be automatically appended if no dot is present in the name.  
The workaround is as simple as that:  since <em>blah.</em> and <em>blah</em> denote the 
same file (at list on FAT and HPFS file systems), to start an executable residing in file <em>n:/bin/blah</em> (no 
extension) give an argument <code>n:/bin/blah.</code> (dot appended) to system().</p>
<p>Perl will start PM programs from VIO (=text-mode) Perl process in a
separate PM session;
the opposite is not true: when you start a non-PM program from a PM
Perl process, Perl would not run it in a separate session.  If a separate
session is desired, either ensure
that shell will be used, as in <code>system 'cmd /c myprog'</code>, or start it using
optional arguments to <a href="../../lib/Pod/perlfunc.html#item_system"><code>system()</code></a> documented in <code>OS2::Process</code> module.  This
is considered to be a feature.</p>
<p>
</p>
<hr />
<h1><a name="frequently_asked_questions">Frequently asked questions</a></h1>
<p>
</p>
<h2><a name="it_does_not_work">&quot;It does not work&quot;</a></h2>
<p>Perl binary distributions come with a <em>testperl.cmd</em> script which tries
to detect common problems with misconfigured installations.  There is a
pretty large chance it will discover which step of the installation you
managed to goof.  <code>;-)</code></p>
<p>
</p>
<h2><a name="i_cannot_run_external_programs">I cannot run external programs</a></h2>
<ul>
<li>
<p>Did you run your programs with <a href="../../lib/Pod/perlrun.html#item__2dw"><code>-w</code></a> switch? See 
<em>Starting OS/2 (and DOS) programs under Perl</em>.</p>
</li>
<li>
<p>Do you try to run <em>internal</em> shell commands, like <code>`copy a b`</code>
(internal for <em>cmd.exe</em>), or <code>`glob a*b`</code> (internal for ksh)? You
need to specify your shell explicitly, like <code>`cmd /c copy a b`</code>,
since Perl cannot deduce which commands are internal to your shell.</p>
</li>
</ul>
<p>
</p>
<h2><a name="i_cannot_embed_perl_into_my_program__or_use_perl_dll_from_my_program_">I cannot embed perl into my program, or use <em>perl.dll</em> from my
program.</a></h2>
<dl>
<dt><strong><a name="item_is_your_program_emx_2dcompiled_with__2dzmt__2dzcrt">Is your program EMX-compiled with <code>-Zmt -Zcrtdll</code>?</a></strong>

<dd>
<p>Well, nowadays Perl DLL should be usable from a differently compiled
program too...  If you can run Perl code from REXX scripts (see
<a href="../../OS2/REXX.html">the OS2::REXX manpage</a>), then there are some other aspect of interaction which
are overlooked by the current hackish code to support
differently-compiled principal programs.</p>
</dd>
<dd>
<p>If everything else fails, you need to build a stand-alone DLL for
perl. Contact me, I did it once. Sockets would not work, as a lot of
other stuff.</p>
</dd>
</li>
<dt><strong><a name="item_did_you_use_extutils_3a_3aembed_3f">Did you use <a href="../../lib/ExtUtils/Embed.html">the ExtUtils::Embed manpage</a>?</a></strong>

<dd>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?