expect.examples.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 54 行 · 第 1/2 页
HTML
54 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Examples</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="expect.constants.html">Predefined Constants</a></div> <div class="next" style="text-align: right; float: right;"><a href="ref.expect.html">Expect Functions</a></div> <div class="up"><a href="book.expect.html">Expect</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div> <h1>Examples</h1> <div id="expect.examples-usage" class="section"> <h2 class="title">Expect Usage Examples</h2> <div class="example"> <p><b>Example #1 Expect Usage Example</b></p> <div class="example-contents"><p> This example connects to the remote host via SSH, and prints the remote uptime. </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">"expect.loguser"</span><span style="color: #007700">, </span><span style="color: #DD0000">"Off"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stream </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"expect://ssh root@remotehost uptime"</span><span style="color: #007700">, </span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$cases </span><span style="color: #007700">= array (<br /> array (</span><span style="color: #0000BB">0 </span><span style="color: #007700">=> </span><span style="color: #DD0000">"password:"</span><span style="color: #007700">, </span><span style="color: #0000BB">1 </span><span style="color: #007700">=> </span><span style="color: #0000BB">PASSWORD</span><span style="color: #007700">)<br />);<br /><br />switch (</span><span style="color: #0000BB">expect_expectl </span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">, </span><span style="color: #0000BB">$cases</span><span style="color: #007700">)) {<br /> case </span><span style="color: #0000BB">PASSWORD</span><span style="color: #007700">:<br /> </span><span style="color: #0000BB">fwrite </span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">, </span><span style="color: #DD0000">"password\n"</span><span style="color: #007700">);<br /> break;<br /> <br /> default:<br /> die (</span><span style="color: #DD0000">"Error was occurred while connecting to the remote host!\n"</span><span style="color: #007700">);<br />}<br /><br />while (</span><span style="color: #0000BB">$line </span><span style="color: #007700">= </span><span style="color: #0000BB">fgets</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">)) {<br /> print </span><span style="color: #0000BB">$line</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">fclose </span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span></span></code></div>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?