📄 cgiprogramming.mht
字号:
#-----------------------------
</FONT></PRE></FONT></TD></TR></TBODY></TABLE></DIV>
<DIV class=3DSECT2>
<H2 class=3DSECT2><A name=3DAEN1025>Executing Commands Without Shell=20
Escapes</A></H2>
<TABLE width=3D"100%" bgColor=3D#2f4f4f border=3D0>
<TBODY>
<TR>
<TD><PRE class=3DSCREEN><FONT color=3D#f5deb3 size=3D+1><FONT =
color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#98fb98>system</FONT><FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>"command $input =
</FONT><FONT color=3D#cdad00>@files</FONT><FONT =
color=3D#00cd00>"</FONT><FONT color=3D#00ffff>);</FONT> <FONT =
color=3D#bebebe># UNSAFE
#-----------------------------
</FONT><FONT color=3D#98fb98>system</FONT><FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>"command"</FONT>, $input, =
<FONT color=3D#cdad00>@files</FONT><FONT color=3D#00ffff>);</FONT> =
<FONT color=3D#bebebe># safer
#-----------------------------
</FONT><FONT color=3D#ff7f50>chomp</FONT><FONT =
color=3D#00ffff>(</FONT>$now =3D <FONT =
color=3D#00cd00>`date`</FONT><FONT color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#cdad00>@output</FONT> =3D <FONT =
color=3D#00cd00>`grep $input </FONT><FONT =
color=3D#cdad00>@files</FONT><FONT color=3D#00cd00>`</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#ffa500>die</FONT> <FONT color=3D#00cd00>"cannot =
fork: $!"</FONT> <FONT color=3D#ffa500>unless</FONT> <FONT =
color=3D#ff7f50>defined</FONT> <FONT color=3D#00ffff>(</FONT>$pid =3D =
<FONT color=3D#98fb98>open</FONT><FONT color=3D#00ffff>(</FONT>SAFE_KID, =
<FONT color=3D#00cd00>"|-"</FONT><FONT color=3D#00ffff>));</FONT>
<FONT color=3D#ffa500>if</FONT> <FONT color=3D#00ffff>(</FONT>$pid =
=3D=3D <FONT color=3D#cdcd00>0</FONT><FONT color=3D#00ffff>)</FONT> =
<FONT color=3D#00ffff>{</FONT>
<FONT color=3D#ffa500>exec</FONT><FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>'grep'</FONT>, $input, <FONT =
color=3D#cdad00>@files</FONT><FONT color=3D#00ffff>)</FONT> <FONT =
color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> <FONT =
color=3D#00cd00>"can't exec grep: $!"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#00ffff>}</FONT> <FONT color=3D#ffa500>else</FONT> <FONT =
color=3D#00ffff>{</FONT>
<FONT color=3D#cdad00>@output</FONT> =3D <SAFE_KID><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#98fb98>close</FONT> SAFE_KID<FONT =
color=3D#00ffff>;</FONT> <FONT color=3D#bebebe># $? =
contains status
</FONT><FONT color=3D#00ffff>}</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#98fb98>open</FONT><FONT =
color=3D#00ffff>(</FONT>KID_TO_READ, <FONT color=3D#00cd00>"$program =
</FONT><FONT color=3D#cdad00>@options</FONT><FONT color=3D#00cd00> =
</FONT><FONT color=3D#cdad00>@args</FONT><FONT color=3D#00cd00> =
|"</FONT><FONT color=3D#00ffff>);</FONT> <FONT color=3D#bebebe># =
UNSAFE
#-----------------------------
# add error processing as above
</FONT><FONT color=3D#ffa500>die</FONT> <FONT color=3D#00cd00>"cannot =
fork: $!"</FONT> <FONT color=3D#ffa500>unless</FONT> <FONT =
color=3D#ff7f50>defined</FONT><FONT color=3D#00ffff>(</FONT>$pid =3D =
<FONT color=3D#98fb98>open</FONT><FONT =
color=3D#00ffff>(</FONT>KID_TO_READ, <FONT =
color=3D#00cd00>"-|"</FONT><FONT color=3D#00ffff>));</FONT>
<FONT color=3D#ffa500>if</FONT> <FONT color=3D#00ffff>(</FONT>$pid<FONT =
color=3D#00ffff>)</FONT> <FONT color=3D#00ffff>{</FONT> <FONT =
color=3D#bebebe># parent
</FONT> <FONT color=3D#ffa500>while</FONT> <FONT =
color=3D#00ffff>(</FONT><KID_TO_READ><FONT =
color=3D#00ffff>)</FONT> <FONT color=3D#00ffff>{</FONT>
<FONT color=3D#bebebe># do something interesting
</FONT> <FONT color=3D#00ffff>}</FONT>
<FONT color=3D#98fb98>close</FONT><FONT =
color=3D#00ffff>(</FONT>KID_TO_READ<FONT color=3D#00ffff>)</FONT> =
<FONT color=3D#98fb98>or</FONT> <FONT color=3D#98fb98>warn</FONT> =
<FONT color=3D#00cd00>"kid exited $?"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#00ffff>}</FONT> <FONT color=3D#ffa500>else</FONT> <FONT =
color=3D#00ffff>{</FONT> <FONT color=3D#bebebe># child
</FONT> <FONT color=3D#bebebe># reconfigure, then
</FONT> <FONT color=3D#ffa500>exec</FONT><FONT =
color=3D#00ffff>(</FONT>$program, <FONT color=3D#cdad00>@options</FONT>, =
<FONT color=3D#cdad00>@args</FONT><FONT color=3D#00ffff>)</FONT> <FONT =
color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> <FONT =
color=3D#00cd00>"can't exec program: $!"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#00ffff>}</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#98fb98>open</FONT><FONT =
color=3D#00ffff>(</FONT>KID_TO_WRITE, <FONT color=3D#00cd00>"|$program =
$options </FONT><FONT color=3D#cdad00>@args</FONT><FONT =
color=3D#00cd00>"</FONT><FONT color=3D#00ffff>);</FONT> <FONT =
color=3D#bebebe># UNSAFE
#-----------------------------
</FONT>$pid =3D <FONT color=3D#98fb98>open</FONT><FONT =
color=3D#00ffff>(</FONT>KID_TO_WRITE, <FONT =
color=3D#00cd00>"|-"</FONT><FONT color=3D#00ffff>);</FONT>
<FONT color=3D#ffa500>die</FONT> <FONT color=3D#00cd00>"cannot fork: =
$!"</FONT> <FONT color=3D#ffa500>unless</FONT> <FONT =
color=3D#ff7f50>defined</FONT><FONT color=3D#00ffff>(</FONT>$pid =3D =
<FONT color=3D#98fb98>open</FONT><FONT =
color=3D#00ffff>(</FONT>KID_TO_WRITE, <FONT =
color=3D#00cd00>"|-"</FONT><FONT color=3D#00ffff>));</FONT>
<FONT color=3D#cdcd00>$SIG</FONT><FONT color=3D#00ffff>{</FONT><FONT =
color=3D#00cd00>ALRM</FONT><FONT color=3D#00ffff>}</FONT> =3D <FONT =
color=3D#ffa500>sub</FONT> <FONT color=3D#00ffff>{</FONT> <FONT =
color=3D#ffa500>die</FONT> <FONT color=3D#00cd00>"whoops, $program pipe =
broke"</FONT> <FONT color=3D#00ffff>};</FONT>
<FONT color=3D#ffa500>if</FONT> <FONT color=3D#00ffff>(</FONT>$pid<FONT =
color=3D#00ffff>)</FONT> <FONT color=3D#00ffff>{</FONT> <FONT =
color=3D#bebebe># parent
</FONT> <FONT color=3D#ffa500>for</FONT> <FONT =
color=3D#00ffff>(</FONT><FONT color=3D#cdad00>@data</FONT><FONT =
color=3D#00ffff>)</FONT> <FONT color=3D#00ffff>{</FONT> <FONT =
color=3D#ff7f50>print</FONT> KID_TO_WRITE $_ <FONT =
color=3D#00ffff>}</FONT>
<FONT color=3D#98fb98>close</FONT><FONT =
color=3D#00ffff>(</FONT>KID_TO_WRITE<FONT color=3D#00ffff>)</FONT> =
<FONT color=3D#98fb98>or</FONT> <FONT color=3D#98fb98>warn</FONT> =
<FONT color=3D#00cd00>"kid exited $?"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#00ffff>}</FONT> <FONT color=3D#ffa500>else</FONT> <FONT =
color=3D#00ffff>{</FONT> <FONT color=3D#bebebe># child
</FONT> <FONT color=3D#bebebe># reconfigure, then
</FONT> <FONT color=3D#ffa500>exec</FONT><FONT =
color=3D#00ffff>(</FONT>$program, <FONT color=3D#cdad00>@options</FONT>, =
<FONT color=3D#cdad00>@args</FONT><FONT color=3D#00ffff>)</FONT> <FONT =
color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> <FONT =
color=3D#00cd00>"can't exec program: $!"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#00ffff>}</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT></PRE></FONT></TD></TR></TBODY></TABLE></DIV>
<DIV class=3DSECT2>
<H2 class=3DSECT2><A name=3DAEN1028>Formatting Lists and Tables with =
HTML=20
Shortcuts</A></H2>
<TABLE width=3D"100%" bgColor=3D#2f4f4f border=3D0>
<TBODY>
<TR>
<TD><PRE class=3DSCREEN><FONT color=3D#f5deb3 size=3D+1><FONT =
color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#ff7f50>print</FONT> ol<FONT =
color=3D#00ffff>(</FONT> li<FONT color=3D#00ffff>([</FONT> <FONT =
color=3D#ff7f50>qw</FONT><FONT color=3D#00ffff>(</FONT>red blue =
green<FONT color=3D#00ffff>)])</FONT> <FONT color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe># <OL><LI>red</LI> =
<LI>blue</LI> <LI>green</LI></OL>
</FONT>
<FONT color=3D#cdad00>@names</FONT> =3D <FONT =
color=3D#ff7f50>qw</FONT><FONT color=3D#00ffff>(</FONT>Larry Moe =
Curly<FONT color=3D#00ffff>);</FONT>
<FONT color=3D#ff7f50>print</FONT> ul<FONT color=3D#00ffff>(</FONT> =
li<FONT color=3D#00ffff>({</FONT> <FONT color=3D#00cd00>-TYPE</FONT> =
=3D> <FONT color=3D#00cd00>"disc"</FONT> <FONT =
color=3D#00ffff>}</FONT>, \<FONT color=3D#cdad00>@names</FONT><FONT =
color=3D#00ffff>)</FONT> <FONT color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe># <UL><LI =
TYPE=3D"disc">Larry</LI> <LI TYPE=3D"disc">Moe</LI>
#
# <LI TYPE=3D"disc">Curly</LI></UL>
#-----------------------------
</FONT><FONT color=3D#ff7f50>print</FONT> li<FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>"alpha"</FONT><FONT =
color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe># <LI>alpha</LI>
</FONT>
<FONT color=3D#ff7f50>print</FONT> li<FONT color=3D#00ffff>(</FONT> =
<FONT color=3D#00ffff>[</FONT> <FONT color=3D#00cd00>"alpha"</FONT>, =
<FONT color=3D#00cd00>"omega"</FONT><FONT color=3D#00ffff>]</FONT> <FONT =
color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe># <LI>alpha</LI> =
<LI>omega</LI>
#-----------------------------
</FONT><FONT color=3D#ffa500>use</FONT> <FONT color=3D#b2dfee>CGI</FONT> =
<FONT color=3D#ff7f50>qw</FONT><FONT color=3D#00ffff>(</FONT>:standard =
:html3<FONT color=3D#00ffff>);</FONT>
<FONT color=3D#cdcd00>%hash</FONT> =3D <FONT color=3D#00ffff>(</FONT>
<FONT color=3D#00cd00>"Wisconsin"</FONT> =3D> <FONT =
color=3D#00ffff>[</FONT> <FONT color=3D#00cd00>"Superior"</FONT>, <FONT =
color=3D#00cd00>"Lake Geneva"</FONT>, <FONT =
color=3D#00cd00>"Madison"</FONT> <FONT color=3D#00ffff>]</FONT>,
<FONT color=3D#00cd00>"Colorado"</FONT> =3D> <FONT =
color=3D#00ffff>[</FONT> <FONT color=3D#00cd00>"Denver"</FONT>, <FONT =
color=3D#00cd00>"Fort Collins"</FONT>, <FONT =
color=3D#00cd00>"Boulder"</FONT> <FONT color=3D#00ffff>]</FONT>,
<FONT color=3D#00cd00>"Texas"</FONT> =3D> <FONT =
color=3D#00ffff>[</FONT> <FONT color=3D#00cd00>"Plano"</FONT>, <FONT =
color=3D#00cd00>"Austin"</FONT>, <FONT color=3D#00cd00>"Fort =
Stockton"</FONT> <FONT color=3D#00ffff>]</FONT>,
<FONT color=3D#00cd00>"California"</FONT> =3D> <FONT =
color=3D#00ffff>[</FONT> <FONT color=3D#00cd00>"Sebastopol"</FONT>, =
<FONT color=3D#00cd00>"Santa Rosa"</FONT>, <FONT =
color=3D#00cd00>"Berkeley"</FONT> <FONT color=3D#00ffff>]</FONT>,
<FONT color=3D#00ffff>);</FONT>
$\ =3D <FONT color=3D#00cd00>"\n"</FONT><FONT color=3D#00ffff>;</FONT>
<FONT color=3D#ff7f50>print</FONT> <FONT color=3D#00cd00>"<TABLE> =
<CAPTION>Cities I Have Known</CAPTION>"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#ff7f50>print</FONT> Tr<FONT color=3D#00ffff>(</FONT>th =
<FONT color=3D#00ffff>[</FONT><FONT color=3D#ff7f50>qw</FONT><FONT =
color=3D#00ffff>(</FONT>State Cities<FONT color=3D#00ffff>)]);</FONT>
<FONT color=3D#ffa500>for</FONT> <FONT color=3D#9ac0cd>$k</FONT> <FONT =
color=3D#00ffff>(</FONT><FONT color=3D#ff7f50>sort</FONT> <FONT =
color=3D#ff7f50>keys</FONT> <FONT color=3D#cdcd00>%hash</FONT><FONT =
color=3D#00ffff>)</FONT> <FONT color=3D#00ffff>{</FONT>
<FONT color=3D#ff7f50>print</FONT> Tr<FONT =
color=3D#00ffff>(</FONT>th<FONT color=3D#00ffff>(</FONT>$k<FONT =
color=3D#00ffff>)</FONT>, td<FONT color=3D#00ffff>(</FONT> <FONT =
color=3D#00ffff>[</FONT> <FONT color=3D#ff7f50>sort</FONT> @<FONT =
color=3D#00ffff>{</FONT><FONT color=3D#cdcd00>$hash</FONT><FONT =
color=3D#00ffff>{</FONT>$k<FONT color=3D#00ffff>}}</FONT> <FONT =
color=3D#00ffff>]</FONT> <FONT color=3D#00ffff>));</FONT>
<FONT color=3D#00ffff>}</FONT>
<FONT color=3D#ff7f50>print</FONT> <FONT =
color=3D#00cd00>"</TABLE>"</FONT><FONT color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
# <TABLE> <CAPTION>Cities I Have Known</CAPTION>
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
# <TR><TH>State</TH> =
<TH>Cities</TH></TR>
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
# <TR><TH>California</TH> =
<TD>Berkeley</TD> <TD>Santa =
Rosa</TD></FONT><FONT color=3D#43cd80> </FONT><FONT =
color=3D#bebebe>
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
# <TD>Sebastopol</TD> </TR>
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
# <TR><TH>Colorado</TH> =
<TD>Boulder</TD> <TD>Denver</TD></FONT><FONT =
color=3D#43cd80> </FONT><FONT color=3D#bebebe>
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
# <TD>Fort Collins</TD> </TR>
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
# <TR><TH>Texas</TH> <TD>Austin</TD> =
<TD>Fort Stockton</TD></FONT><FONT color=3D#43cd80> =
</FONT><FONT color=3D#bebebe>
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
# <TD>Plano</TD></TR>
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
# <TR><TH>Wisconsin</TH> <TD>Lake =
Geneva</TD> <TD>Madison</TD></FONT><FONT =
color=3D#43cd80> </FONT><FONT color=3D#bebebe>
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
# <TD>Superior</TD></TR>
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
# </TABLE>
#-----------------------------
</FONT><FONT color=3D#ff7f50>print</FONT> table
caption<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>'Cities I have Known'</FONT><FONT =
color=3D#00ffff>)</FONT>,
Tr<FONT color=3D#00ffff>(</FONT>th <FONT =
color=3D#00ffff>[</FONT><FONT color=3D#ff7f50>qw</FONT><FONT =
color=3D#00ffff>(</FONT>State Cities<FONT color=3D#00ffff>)])</FONT>,
<FONT color=3D#ff7f50>map</FONT> <FONT color=3D#00ffff>{</FONT> =
Tr<FONT color=3D#00ffff>(</FONT>th<FONT color=3D#00ffff>(</FONT>$_<FONT =
color=3D#00ffff>)</FONT>, td<FONT color=3D#00ffff>(</FONT> <FONT =
color=3D#00ffff>[</FONT> <FONT color=3D#ff7f50>sort</FONT> @<FONT =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -