0857e0d5b59d45b52870fe3164dc8b2fdeffa27c
[progcomp10.git] / src / link / pexpect / doc / pexpect.html
1
2 <!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
3 <html><head><title>Python: module pexpect</title>
4 </head><body bgcolor="#f0f0f8">
5
6 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
7 <tr bgcolor="#7799ee">
8 <td valign=bottom>&nbsp;<br>
9 <font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>pexpect</strong></big></big> (version 2.3)</font></td
10 ><td align=right valign=bottom
11 ><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/noah/pexpect/trunk/pexpect/pexpect.py">/home/noah/pexpect/trunk/pexpect/pexpect.py</a></font></td></tr></table>
12     <p><tt>Pexpect&nbsp;is&nbsp;a&nbsp;Python&nbsp;module&nbsp;for&nbsp;spawning&nbsp;child&nbsp;applications&nbsp;and&nbsp;controlling<br>
13 them&nbsp;automatically.&nbsp;Pexpect&nbsp;can&nbsp;be&nbsp;used&nbsp;for&nbsp;automating&nbsp;interactive&nbsp;applications<br>
14 such&nbsp;as&nbsp;ssh,&nbsp;ftp,&nbsp;passwd,&nbsp;telnet,&nbsp;etc.&nbsp;It&nbsp;can&nbsp;be&nbsp;used&nbsp;to&nbsp;a&nbsp;automate&nbsp;setup<br>
15 scripts&nbsp;for&nbsp;duplicating&nbsp;software&nbsp;package&nbsp;installations&nbsp;on&nbsp;different&nbsp;servers.&nbsp;It<br>
16 can&nbsp;be&nbsp;used&nbsp;for&nbsp;automated&nbsp;software&nbsp;testing.&nbsp;Pexpect&nbsp;is&nbsp;in&nbsp;the&nbsp;spirit&nbsp;of&nbsp;Don<br>
17 Libes'&nbsp;Expect,&nbsp;but&nbsp;Pexpect&nbsp;is&nbsp;pure&nbsp;Python.&nbsp;Other&nbsp;Expect-like&nbsp;modules&nbsp;for&nbsp;Python<br>
18 require&nbsp;TCL&nbsp;and&nbsp;Expect&nbsp;or&nbsp;require&nbsp;C&nbsp;extensions&nbsp;to&nbsp;be&nbsp;compiled.&nbsp;Pexpect&nbsp;does&nbsp;not<br>
19 use&nbsp;C,&nbsp;Expect,&nbsp;or&nbsp;TCL&nbsp;extensions.&nbsp;It&nbsp;should&nbsp;work&nbsp;on&nbsp;any&nbsp;platform&nbsp;that&nbsp;supports<br>
20 the&nbsp;standard&nbsp;Python&nbsp;pty&nbsp;module.&nbsp;The&nbsp;Pexpect&nbsp;interface&nbsp;focuses&nbsp;on&nbsp;ease&nbsp;of&nbsp;use&nbsp;so<br>
21 that&nbsp;simple&nbsp;tasks&nbsp;are&nbsp;easy.<br>
22 &nbsp;<br>
23 There&nbsp;are&nbsp;two&nbsp;main&nbsp;interfaces&nbsp;to&nbsp;Pexpect&nbsp;--&nbsp;the&nbsp;function,&nbsp;<a href="#-run">run</a>()&nbsp;and&nbsp;the&nbsp;class,<br>
24 <a href="#spawn">spawn</a>.&nbsp;You&nbsp;can&nbsp;call&nbsp;the&nbsp;<a href="#-run">run</a>()&nbsp;function&nbsp;to&nbsp;execute&nbsp;a&nbsp;command&nbsp;and&nbsp;return&nbsp;the<br>
25 output.&nbsp;This&nbsp;is&nbsp;a&nbsp;handy&nbsp;replacement&nbsp;for&nbsp;os.system().<br>
26 &nbsp;<br>
27 For&nbsp;example::<br>
28 &nbsp;<br>
29 &nbsp;&nbsp;&nbsp;&nbsp;pexpect.<a href="#-run">run</a>('ls&nbsp;-la')<br>
30 &nbsp;<br>
31 The&nbsp;more&nbsp;powerful&nbsp;interface&nbsp;is&nbsp;the&nbsp;<a href="#spawn">spawn</a>&nbsp;class.&nbsp;You&nbsp;can&nbsp;use&nbsp;this&nbsp;to&nbsp;<a href="#spawn">spawn</a>&nbsp;an<br>
32 external&nbsp;child&nbsp;command&nbsp;and&nbsp;then&nbsp;interact&nbsp;with&nbsp;the&nbsp;child&nbsp;by&nbsp;sending&nbsp;lines&nbsp;and<br>
33 expecting&nbsp;responses.<br>
34 &nbsp;<br>
35 For&nbsp;example::<br>
36 &nbsp;<br>
37 &nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>('scp&nbsp;foo&nbsp;[email protected]:.')<br>
38 &nbsp;&nbsp;&nbsp;&nbsp;child.expect&nbsp;('Password:')<br>
39 &nbsp;&nbsp;&nbsp;&nbsp;child.sendline&nbsp;(mypassword)<br>
40 &nbsp;<br>
41 This&nbsp;works&nbsp;even&nbsp;for&nbsp;commands&nbsp;that&nbsp;ask&nbsp;for&nbsp;passwords&nbsp;or&nbsp;other&nbsp;input&nbsp;outside&nbsp;of<br>
42 the&nbsp;normal&nbsp;stdio&nbsp;streams.<br>
43 &nbsp;<br>
44 Credits:&nbsp;Noah&nbsp;Spurrier,&nbsp;Richard&nbsp;Holden,&nbsp;Marco&nbsp;Molteni,&nbsp;Kimberley&nbsp;Burchett,<br>
45 Robert&nbsp;Stone,&nbsp;Hartmut&nbsp;Goebel,&nbsp;Chad&nbsp;Schroeder,&nbsp;Erick&nbsp;Tryzelaar,&nbsp;Dave&nbsp;Kirby,&nbsp;Ids<br>
46 vander&nbsp;Molen,&nbsp;George&nbsp;Todd,&nbsp;Noel&nbsp;Taylor,&nbsp;Nicolas&nbsp;D.&nbsp;Cesar,&nbsp;Alexander&nbsp;Gattin,<br>
47 Geoffrey&nbsp;Marshall,&nbsp;Francisco&nbsp;Lourenco,&nbsp;Glen&nbsp;Mabey,&nbsp;Karthik&nbsp;Gurusamy,&nbsp;Fernando<br>
48 Perez,&nbsp;Corey&nbsp;Minyard,&nbsp;Jon&nbsp;Cohen,&nbsp;Guillaume&nbsp;Chazarain,&nbsp;Andrew&nbsp;Ryan,&nbsp;Nick<br>
49 Craig-Wood,&nbsp;Andrew&nbsp;Stone,&nbsp;Jorgen&nbsp;Grahn&nbsp;(Let&nbsp;me&nbsp;know&nbsp;if&nbsp;I&nbsp;forgot&nbsp;anyone.)<br>
50 &nbsp;<br>
51 Free,&nbsp;open&nbsp;source,&nbsp;and&nbsp;all&nbsp;that&nbsp;good&nbsp;stuff.<br>
52 &nbsp;<br>
53 Permission&nbsp;is&nbsp;hereby&nbsp;granted,&nbsp;free&nbsp;of&nbsp;charge,&nbsp;to&nbsp;any&nbsp;person&nbsp;obtaining&nbsp;a&nbsp;copy&nbsp;of<br>
54 this&nbsp;software&nbsp;and&nbsp;associated&nbsp;documentation&nbsp;files&nbsp;(the&nbsp;"Software"),&nbsp;to&nbsp;deal&nbsp;in<br>
55 the&nbsp;Software&nbsp;without&nbsp;restriction,&nbsp;including&nbsp;without&nbsp;limitation&nbsp;the&nbsp;rights&nbsp;to<br>
56 use,&nbsp;copy,&nbsp;modify,&nbsp;merge,&nbsp;publish,&nbsp;distribute,&nbsp;sublicense,&nbsp;and/or&nbsp;sell&nbsp;copies<br>
57 of&nbsp;the&nbsp;Software,&nbsp;and&nbsp;to&nbsp;permit&nbsp;persons&nbsp;to&nbsp;whom&nbsp;the&nbsp;Software&nbsp;is&nbsp;furnished&nbsp;to&nbsp;do<br>
58 so,&nbsp;subject&nbsp;to&nbsp;the&nbsp;following&nbsp;conditions:<br>
59 &nbsp;<br>
60 The&nbsp;above&nbsp;copyright&nbsp;notice&nbsp;and&nbsp;this&nbsp;permission&nbsp;notice&nbsp;shall&nbsp;be&nbsp;included&nbsp;in&nbsp;all<br>
61 copies&nbsp;or&nbsp;substantial&nbsp;portions&nbsp;of&nbsp;the&nbsp;Software.<br>
62 &nbsp;<br>
63 THE&nbsp;SOFTWARE&nbsp;IS&nbsp;PROVIDED&nbsp;"AS&nbsp;IS",&nbsp;WITHOUT&nbsp;WARRANTY&nbsp;OF&nbsp;ANY&nbsp;KIND,&nbsp;EXPRESS&nbsp;OR<br>
64 IMPLIED,&nbsp;INCLUDING&nbsp;BUT&nbsp;NOT&nbsp;LIMITED&nbsp;TO&nbsp;THE&nbsp;WARRANTIES&nbsp;OF&nbsp;MERCHANTABILITY,<br>
65 FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR&nbsp;PURPOSE&nbsp;AND&nbsp;NONINFRINGEMENT.&nbsp;IN&nbsp;NO&nbsp;EVENT&nbsp;SHALL&nbsp;THE<br>
66 AUTHORS&nbsp;OR&nbsp;COPYRIGHT&nbsp;HOLDERS&nbsp;BE&nbsp;LIABLE&nbsp;FOR&nbsp;ANY&nbsp;CLAIM,&nbsp;DAMAGES&nbsp;OR&nbsp;OTHER<br>
67 LIABILITY,&nbsp;WHETHER&nbsp;IN&nbsp;AN&nbsp;ACTION&nbsp;OF&nbsp;CONTRACT,&nbsp;TORT&nbsp;OR&nbsp;OTHERWISE,&nbsp;ARISING&nbsp;FROM,<br>
68 OUT&nbsp;OF&nbsp;OR&nbsp;IN&nbsp;CONNECTION&nbsp;WITH&nbsp;THE&nbsp;SOFTWARE&nbsp;OR&nbsp;THE&nbsp;USE&nbsp;OR&nbsp;OTHER&nbsp;DEALINGS&nbsp;IN&nbsp;THE<br>
69 SOFTWARE.<br>
70 &nbsp;<br>
71 Pexpect&nbsp;Copyright&nbsp;(c)&nbsp;2008&nbsp;Noah&nbsp;Spurrier<br>
72 <a href="http://pexpect.sourceforge.net/">http://pexpect.sourceforge.net/</a><br>
73 &nbsp;<br>
74 $Id:&nbsp;pexpect.py&nbsp;507&nbsp;2007-12-27&nbsp;02:40:52Z&nbsp;noah&nbsp;$</tt></p>
75 <p>
76 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
77 <tr bgcolor="#aa55cc">
78 <td colspan=3 valign=bottom>&nbsp;<br>
79 <font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
80     
81 <tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
82 <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="errno.html">errno</a><br>
83 <a href="fcntl.html">fcntl</a><br>
84 <a href="os.html">os</a><br>
85 <a href="pty.html">pty</a><br>
86 </td><td width="25%" valign=top><a href="re.html">re</a><br>
87 <a href="resource.html">resource</a><br>
88 <a href="select.html">select</a><br>
89 <a href="signal.html">signal</a><br>
90 </td><td width="25%" valign=top><a href="string.html">string</a><br>
91 <a href="struct.html">struct</a><br>
92 <a href="sys.html">sys</a><br>
93 <a href="termios.html">termios</a><br>
94 </td><td width="25%" valign=top><a href="time.html">time</a><br>
95 <a href="traceback.html">traceback</a><br>
96 <a href="tty.html">tty</a><br>
97 <a href="types.html">types</a><br>
98 </td></tr></table></td></tr></table><p>
99 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
100 <tr bgcolor="#ee77aa">
101 <td colspan=3 valign=bottom>&nbsp;<br>
102 <font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
103     
104 <tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
105 <td width="100%"><dl>
106 <dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
107 </font></dt><dd>
108 <dl>
109 <dt><font face="helvetica, arial"><a href="pexpect.html#spawn">spawn</a>
110 </font></dt></dl>
111 </dd>
112 <dt><font face="helvetica, arial"><a href="exceptions.html#Exception">exceptions.Exception</a>(<a href="exceptions.html#BaseException">exceptions.BaseException</a>)
113 </font></dt><dd>
114 <dl>
115 <dt><font face="helvetica, arial"><a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a>
116 </font></dt><dd>
117 <dl>
118 <dt><font face="helvetica, arial"><a href="pexpect.html#EOF">EOF</a>
119 </font></dt><dt><font face="helvetica, arial"><a href="pexpect.html#TIMEOUT">TIMEOUT</a>
120 </font></dt></dl>
121 </dd>
122 </dl>
123 </dd>
124 </dl>
125  <p>
126 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
127 <tr bgcolor="#ffc8d8">
128 <td colspan=3 valign=bottom>&nbsp;<br>
129 <font color="#000000" face="helvetica, arial"><a name="EOF">class <strong>EOF</strong></a>(<a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a>)</font></td></tr>
130     
131 <tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
132 <td colspan=2><tt>Raised&nbsp;when&nbsp;<a href="#EOF">EOF</a>&nbsp;is&nbsp;read&nbsp;from&nbsp;a&nbsp;child.&nbsp;This&nbsp;usually&nbsp;means&nbsp;the&nbsp;child&nbsp;has&nbsp;exited.<br>&nbsp;</tt></td></tr>
133 <tr><td>&nbsp;</td>
134 <td width="100%"><dl><dt>Method resolution order:</dt>
135 <dd><a href="pexpect.html#EOF">EOF</a></dd>
136 <dd><a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a></dd>
137 <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd>
138 <dd><a href="exceptions.html#BaseException">exceptions.BaseException</a></dd>
139 <dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
140 </dl>
141 <hr>
142 Methods inherited from <a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a>:<br>
143 <dl><dt><a name="EOF-__init__"><strong>__init__</strong></a>(self, value)</dt></dl>
144
145 <dl><dt><a name="EOF-__str__"><strong>__str__</strong></a>(self)</dt></dl>
146
147 <dl><dt><a name="EOF-get_trace"><strong>get_trace</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;an&nbsp;abbreviated&nbsp;stack&nbsp;trace&nbsp;with&nbsp;lines&nbsp;that&nbsp;only&nbsp;concern<br>
148 the&nbsp;caller.&nbsp;In&nbsp;other&nbsp;words,&nbsp;the&nbsp;stack&nbsp;trace&nbsp;inside&nbsp;the&nbsp;Pexpect&nbsp;module<br>
149 is&nbsp;not&nbsp;included.</tt></dd></dl>
150
151 <hr>
152 Data descriptors inherited from <a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a>:<br>
153 <dl><dt><strong>__weakref__</strong></dt>
154 <dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
155 </dl>
156 <hr>
157 Data and other attributes inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
158 <dl><dt><strong>__new__</strong> = &lt;built-in method __new__ of type object at 0x81400e0&gt;<dd><tt>T.<a href="#EOF-__new__">__new__</a>(S,&nbsp;...)&nbsp;-&gt;&nbsp;a&nbsp;new&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;with&nbsp;type&nbsp;S,&nbsp;a&nbsp;subtype&nbsp;of&nbsp;T</tt></dl>
159
160 <hr>
161 Methods inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
162 <dl><dt><a name="EOF-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#EOF-__delattr__">__delattr__</a>('name')&nbsp;&lt;==&gt;&nbsp;del&nbsp;x.name</tt></dd></dl>
163
164 <dl><dt><a name="EOF-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#EOF-__getattribute__">__getattribute__</a>('name')&nbsp;&lt;==&gt;&nbsp;x.name</tt></dd></dl>
165
166 <dl><dt><a name="EOF-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#EOF-__getitem__">__getitem__</a>(y)&nbsp;&lt;==&gt;&nbsp;x[y]</tt></dd></dl>
167
168 <dl><dt><a name="EOF-__getslice__"><strong>__getslice__</strong></a>(...)</dt><dd><tt>x.<a href="#EOF-__getslice__">__getslice__</a>(i,&nbsp;j)&nbsp;&lt;==&gt;&nbsp;x[i:j]<br>
169 &nbsp;<br>
170 Use&nbsp;of&nbsp;negative&nbsp;indices&nbsp;is&nbsp;not&nbsp;supported.</tt></dd></dl>
171
172 <dl><dt><a name="EOF-__reduce__"><strong>__reduce__</strong></a>(...)</dt></dl>
173
174 <dl><dt><a name="EOF-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#EOF-__repr__">__repr__</a>()&nbsp;&lt;==&gt;&nbsp;repr(x)</tt></dd></dl>
175
176 <dl><dt><a name="EOF-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#EOF-__setattr__">__setattr__</a>('name',&nbsp;value)&nbsp;&lt;==&gt;&nbsp;x.name&nbsp;=&nbsp;value</tt></dd></dl>
177
178 <dl><dt><a name="EOF-__setstate__"><strong>__setstate__</strong></a>(...)</dt></dl>
179
180 <hr>
181 Data descriptors inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
182 <dl><dt><strong>__dict__</strong></dt>
183 </dl>
184 <dl><dt><strong>args</strong></dt>
185 </dl>
186 <dl><dt><strong>message</strong></dt>
187 <dd><tt>exception&nbsp;message</tt></dd>
188 </dl>
189 </td></tr></table> <p>
190 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
191 <tr bgcolor="#ffc8d8">
192 <td colspan=3 valign=bottom>&nbsp;<br>
193 <font color="#000000" face="helvetica, arial"><a name="ExceptionPexpect">class <strong>ExceptionPexpect</strong></a>(<a href="exceptions.html#Exception">exceptions.Exception</a>)</font></td></tr>
194     
195 <tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
196 <td colspan=2><tt>Base&nbsp;class&nbsp;for&nbsp;all&nbsp;exceptions&nbsp;raised&nbsp;by&nbsp;this&nbsp;module.<br>&nbsp;</tt></td></tr>
197 <tr><td>&nbsp;</td>
198 <td width="100%"><dl><dt>Method resolution order:</dt>
199 <dd><a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a></dd>
200 <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd>
201 <dd><a href="exceptions.html#BaseException">exceptions.BaseException</a></dd>
202 <dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
203 </dl>
204 <hr>
205 Methods defined here:<br>
206 <dl><dt><a name="ExceptionPexpect-__init__"><strong>__init__</strong></a>(self, value)</dt></dl>
207
208 <dl><dt><a name="ExceptionPexpect-__str__"><strong>__str__</strong></a>(self)</dt></dl>
209
210 <dl><dt><a name="ExceptionPexpect-get_trace"><strong>get_trace</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;an&nbsp;abbreviated&nbsp;stack&nbsp;trace&nbsp;with&nbsp;lines&nbsp;that&nbsp;only&nbsp;concern<br>
211 the&nbsp;caller.&nbsp;In&nbsp;other&nbsp;words,&nbsp;the&nbsp;stack&nbsp;trace&nbsp;inside&nbsp;the&nbsp;Pexpect&nbsp;module<br>
212 is&nbsp;not&nbsp;included.</tt></dd></dl>
213
214 <hr>
215 Data descriptors defined here:<br>
216 <dl><dt><strong>__weakref__</strong></dt>
217 <dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
218 </dl>
219 <hr>
220 Data and other attributes inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
221 <dl><dt><strong>__new__</strong> = &lt;built-in method __new__ of type object at 0x81400e0&gt;<dd><tt>T.<a href="#ExceptionPexpect-__new__">__new__</a>(S,&nbsp;...)&nbsp;-&gt;&nbsp;a&nbsp;new&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;with&nbsp;type&nbsp;S,&nbsp;a&nbsp;subtype&nbsp;of&nbsp;T</tt></dl>
222
223 <hr>
224 Methods inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
225 <dl><dt><a name="ExceptionPexpect-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#ExceptionPexpect-__delattr__">__delattr__</a>('name')&nbsp;&lt;==&gt;&nbsp;del&nbsp;x.name</tt></dd></dl>
226
227 <dl><dt><a name="ExceptionPexpect-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#ExceptionPexpect-__getattribute__">__getattribute__</a>('name')&nbsp;&lt;==&gt;&nbsp;x.name</tt></dd></dl>
228
229 <dl><dt><a name="ExceptionPexpect-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#ExceptionPexpect-__getitem__">__getitem__</a>(y)&nbsp;&lt;==&gt;&nbsp;x[y]</tt></dd></dl>
230
231 <dl><dt><a name="ExceptionPexpect-__getslice__"><strong>__getslice__</strong></a>(...)</dt><dd><tt>x.<a href="#ExceptionPexpect-__getslice__">__getslice__</a>(i,&nbsp;j)&nbsp;&lt;==&gt;&nbsp;x[i:j]<br>
232 &nbsp;<br>
233 Use&nbsp;of&nbsp;negative&nbsp;indices&nbsp;is&nbsp;not&nbsp;supported.</tt></dd></dl>
234
235 <dl><dt><a name="ExceptionPexpect-__reduce__"><strong>__reduce__</strong></a>(...)</dt></dl>
236
237 <dl><dt><a name="ExceptionPexpect-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#ExceptionPexpect-__repr__">__repr__</a>()&nbsp;&lt;==&gt;&nbsp;repr(x)</tt></dd></dl>
238
239 <dl><dt><a name="ExceptionPexpect-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#ExceptionPexpect-__setattr__">__setattr__</a>('name',&nbsp;value)&nbsp;&lt;==&gt;&nbsp;x.name&nbsp;=&nbsp;value</tt></dd></dl>
240
241 <dl><dt><a name="ExceptionPexpect-__setstate__"><strong>__setstate__</strong></a>(...)</dt></dl>
242
243 <hr>
244 Data descriptors inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
245 <dl><dt><strong>__dict__</strong></dt>
246 </dl>
247 <dl><dt><strong>args</strong></dt>
248 </dl>
249 <dl><dt><strong>message</strong></dt>
250 <dd><tt>exception&nbsp;message</tt></dd>
251 </dl>
252 </td></tr></table> <p>
253 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
254 <tr bgcolor="#ffc8d8">
255 <td colspan=3 valign=bottom>&nbsp;<br>
256 <font color="#000000" face="helvetica, arial"><a name="TIMEOUT">class <strong>TIMEOUT</strong></a>(<a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a>)</font></td></tr>
257     
258 <tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
259 <td colspan=2><tt>Raised&nbsp;when&nbsp;a&nbsp;read&nbsp;time&nbsp;exceeds&nbsp;the&nbsp;timeout.<br>&nbsp;</tt></td></tr>
260 <tr><td>&nbsp;</td>
261 <td width="100%"><dl><dt>Method resolution order:</dt>
262 <dd><a href="pexpect.html#TIMEOUT">TIMEOUT</a></dd>
263 <dd><a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a></dd>
264 <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd>
265 <dd><a href="exceptions.html#BaseException">exceptions.BaseException</a></dd>
266 <dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
267 </dl>
268 <hr>
269 Methods inherited from <a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a>:<br>
270 <dl><dt><a name="TIMEOUT-__init__"><strong>__init__</strong></a>(self, value)</dt></dl>
271
272 <dl><dt><a name="TIMEOUT-__str__"><strong>__str__</strong></a>(self)</dt></dl>
273
274 <dl><dt><a name="TIMEOUT-get_trace"><strong>get_trace</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;an&nbsp;abbreviated&nbsp;stack&nbsp;trace&nbsp;with&nbsp;lines&nbsp;that&nbsp;only&nbsp;concern<br>
275 the&nbsp;caller.&nbsp;In&nbsp;other&nbsp;words,&nbsp;the&nbsp;stack&nbsp;trace&nbsp;inside&nbsp;the&nbsp;Pexpect&nbsp;module<br>
276 is&nbsp;not&nbsp;included.</tt></dd></dl>
277
278 <hr>
279 Data descriptors inherited from <a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a>:<br>
280 <dl><dt><strong>__weakref__</strong></dt>
281 <dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
282 </dl>
283 <hr>
284 Data and other attributes inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
285 <dl><dt><strong>__new__</strong> = &lt;built-in method __new__ of type object at 0x81400e0&gt;<dd><tt>T.<a href="#TIMEOUT-__new__">__new__</a>(S,&nbsp;...)&nbsp;-&gt;&nbsp;a&nbsp;new&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;with&nbsp;type&nbsp;S,&nbsp;a&nbsp;subtype&nbsp;of&nbsp;T</tt></dl>
286
287 <hr>
288 Methods inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
289 <dl><dt><a name="TIMEOUT-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#TIMEOUT-__delattr__">__delattr__</a>('name')&nbsp;&lt;==&gt;&nbsp;del&nbsp;x.name</tt></dd></dl>
290
291 <dl><dt><a name="TIMEOUT-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#TIMEOUT-__getattribute__">__getattribute__</a>('name')&nbsp;&lt;==&gt;&nbsp;x.name</tt></dd></dl>
292
293 <dl><dt><a name="TIMEOUT-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#TIMEOUT-__getitem__">__getitem__</a>(y)&nbsp;&lt;==&gt;&nbsp;x[y]</tt></dd></dl>
294
295 <dl><dt><a name="TIMEOUT-__getslice__"><strong>__getslice__</strong></a>(...)</dt><dd><tt>x.<a href="#TIMEOUT-__getslice__">__getslice__</a>(i,&nbsp;j)&nbsp;&lt;==&gt;&nbsp;x[i:j]<br>
296 &nbsp;<br>
297 Use&nbsp;of&nbsp;negative&nbsp;indices&nbsp;is&nbsp;not&nbsp;supported.</tt></dd></dl>
298
299 <dl><dt><a name="TIMEOUT-__reduce__"><strong>__reduce__</strong></a>(...)</dt></dl>
300
301 <dl><dt><a name="TIMEOUT-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#TIMEOUT-__repr__">__repr__</a>()&nbsp;&lt;==&gt;&nbsp;repr(x)</tt></dd></dl>
302
303 <dl><dt><a name="TIMEOUT-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#TIMEOUT-__setattr__">__setattr__</a>('name',&nbsp;value)&nbsp;&lt;==&gt;&nbsp;x.name&nbsp;=&nbsp;value</tt></dd></dl>
304
305 <dl><dt><a name="TIMEOUT-__setstate__"><strong>__setstate__</strong></a>(...)</dt></dl>
306
307 <hr>
308 Data descriptors inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
309 <dl><dt><strong>__dict__</strong></dt>
310 </dl>
311 <dl><dt><strong>args</strong></dt>
312 </dl>
313 <dl><dt><strong>message</strong></dt>
314 <dd><tt>exception&nbsp;message</tt></dd>
315 </dl>
316 </td></tr></table> <p>
317 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
318 <tr bgcolor="#ffc8d8">
319 <td colspan=3 valign=bottom>&nbsp;<br>
320 <font color="#000000" face="helvetica, arial"><a name="spawn">class <strong>spawn</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
321     
322 <tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
323 <td colspan=2><tt>This&nbsp;is&nbsp;the&nbsp;main&nbsp;class&nbsp;interface&nbsp;for&nbsp;Pexpect.&nbsp;Use&nbsp;this&nbsp;class&nbsp;to&nbsp;start<br>
324 and&nbsp;control&nbsp;child&nbsp;applications.<br>&nbsp;</tt></td></tr>
325 <tr><td>&nbsp;</td>
326 <td width="100%">Methods defined here:<br>
327 <dl><dt><a name="spawn-__del__"><strong>__del__</strong></a>(self)</dt><dd><tt>This&nbsp;makes&nbsp;sure&nbsp;that&nbsp;no&nbsp;system&nbsp;resources&nbsp;are&nbsp;left&nbsp;open.&nbsp;Python&nbsp;only<br>
328 garbage&nbsp;collects&nbsp;Python&nbsp;objects.&nbsp;OS&nbsp;file&nbsp;descriptors&nbsp;are&nbsp;not&nbsp;Python<br>
329 objects,&nbsp;so&nbsp;they&nbsp;must&nbsp;be&nbsp;handled&nbsp;explicitly.&nbsp;If&nbsp;the&nbsp;child&nbsp;file<br>
330 descriptor&nbsp;was&nbsp;opened&nbsp;outside&nbsp;of&nbsp;this&nbsp;class&nbsp;(passed&nbsp;to&nbsp;the&nbsp;constructor)<br>
331 then&nbsp;this&nbsp;does&nbsp;not&nbsp;close&nbsp;it.</tt></dd></dl>
332
333 <dl><dt><a name="spawn-__init__"><strong>__init__</strong></a>(self, command, args<font color="#909090">=[]</font>, timeout<font color="#909090">=30</font>, maxread<font color="#909090">=2000</font>, searchwindowsize<font color="#909090">=None</font>, logfile<font color="#909090">=None</font>, cwd<font color="#909090">=None</font>, env<font color="#909090">=None</font>)</dt><dd><tt>This&nbsp;is&nbsp;the&nbsp;constructor.&nbsp;The&nbsp;command&nbsp;parameter&nbsp;may&nbsp;be&nbsp;a&nbsp;string&nbsp;that<br>
334 includes&nbsp;a&nbsp;command&nbsp;and&nbsp;any&nbsp;arguments&nbsp;to&nbsp;the&nbsp;command.&nbsp;For&nbsp;example::<br>
335 &nbsp;<br>
336 &nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>&nbsp;('/usr/bin/ftp')<br>
337 &nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>&nbsp;('/usr/bin/ssh&nbsp;[email protected]')<br>
338 &nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>&nbsp;('ls&nbsp;-latr&nbsp;/tmp')<br>
339 &nbsp;<br>
340 You&nbsp;may&nbsp;also&nbsp;construct&nbsp;it&nbsp;with&nbsp;a&nbsp;list&nbsp;of&nbsp;arguments&nbsp;like&nbsp;so::<br>
341 &nbsp;<br>
342 &nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>&nbsp;('/usr/bin/ftp',&nbsp;[])<br>
343 &nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>&nbsp;('/usr/bin/ssh',&nbsp;['[email protected]'])<br>
344 &nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>&nbsp;('ls',&nbsp;['-latr',&nbsp;'/tmp'])<br>
345 &nbsp;<br>
346 After&nbsp;this&nbsp;the&nbsp;child&nbsp;application&nbsp;will&nbsp;be&nbsp;created&nbsp;and&nbsp;will&nbsp;be&nbsp;ready&nbsp;to<br>
347 talk&nbsp;to.&nbsp;For&nbsp;normal&nbsp;use,&nbsp;see&nbsp;<a href="#spawn-expect">expect</a>()&nbsp;and&nbsp;<a href="#spawn-send">send</a>()&nbsp;and&nbsp;<a href="#spawn-sendline">sendline</a>().<br>
348 &nbsp;<br>
349 Remember&nbsp;that&nbsp;Pexpect&nbsp;does&nbsp;NOT&nbsp;interpret&nbsp;shell&nbsp;meta&nbsp;characters&nbsp;such&nbsp;as<br>
350 redirect,&nbsp;pipe,&nbsp;or&nbsp;wild&nbsp;cards&nbsp;(&gt;,&nbsp;|,&nbsp;or&nbsp;*).&nbsp;This&nbsp;is&nbsp;a&nbsp;common&nbsp;mistake.<br>
351 If&nbsp;you&nbsp;want&nbsp;to&nbsp;run&nbsp;a&nbsp;command&nbsp;and&nbsp;pipe&nbsp;it&nbsp;through&nbsp;another&nbsp;command&nbsp;then<br>
352 you&nbsp;must&nbsp;also&nbsp;start&nbsp;a&nbsp;shell.&nbsp;For&nbsp;example::<br>
353 &nbsp;<br>
354 &nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>('/bin/bash&nbsp;-c&nbsp;"ls&nbsp;-l&nbsp;|&nbsp;grep&nbsp;LOG&nbsp;&gt;&nbsp;log_list.txt"')<br>
355 &nbsp;&nbsp;&nbsp;&nbsp;child.<a href="#spawn-expect">expect</a>(pexpect.<a href="#EOF">EOF</a>)<br>
356 &nbsp;<br>
357 The&nbsp;second&nbsp;form&nbsp;of&nbsp;<a href="#spawn">spawn</a>&nbsp;(where&nbsp;you&nbsp;pass&nbsp;a&nbsp;list&nbsp;of&nbsp;arguments)&nbsp;is&nbsp;useful<br>
358 in&nbsp;situations&nbsp;where&nbsp;you&nbsp;wish&nbsp;to&nbsp;<a href="#spawn">spawn</a>&nbsp;a&nbsp;command&nbsp;and&nbsp;pass&nbsp;it&nbsp;its&nbsp;own<br>
359 argument&nbsp;list.&nbsp;This&nbsp;can&nbsp;make&nbsp;syntax&nbsp;more&nbsp;clear.&nbsp;For&nbsp;example,&nbsp;the<br>
360 following&nbsp;is&nbsp;equivalent&nbsp;to&nbsp;the&nbsp;previous&nbsp;example::<br>
361 &nbsp;<br>
362 &nbsp;&nbsp;&nbsp;&nbsp;shell_cmd&nbsp;=&nbsp;'ls&nbsp;-l&nbsp;|&nbsp;grep&nbsp;LOG&nbsp;&gt;&nbsp;log_list.txt'<br>
363 &nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>('/bin/bash',&nbsp;['-c',&nbsp;shell_cmd])<br>
364 &nbsp;&nbsp;&nbsp;&nbsp;child.<a href="#spawn-expect">expect</a>(pexpect.<a href="#EOF">EOF</a>)<br>
365 &nbsp;<br>
366 The&nbsp;maxread&nbsp;attribute&nbsp;sets&nbsp;the&nbsp;read&nbsp;buffer&nbsp;size.&nbsp;This&nbsp;is&nbsp;maximum&nbsp;number<br>
367 of&nbsp;bytes&nbsp;that&nbsp;Pexpect&nbsp;will&nbsp;try&nbsp;to&nbsp;read&nbsp;from&nbsp;a&nbsp;TTY&nbsp;at&nbsp;one&nbsp;time.&nbsp;Setting<br>
368 the&nbsp;maxread&nbsp;size&nbsp;to&nbsp;1&nbsp;will&nbsp;turn&nbsp;off&nbsp;buffering.&nbsp;Setting&nbsp;the&nbsp;maxread<br>
369 value&nbsp;higher&nbsp;may&nbsp;help&nbsp;performance&nbsp;in&nbsp;cases&nbsp;where&nbsp;large&nbsp;amounts&nbsp;of<br>
370 output&nbsp;are&nbsp;read&nbsp;back&nbsp;from&nbsp;the&nbsp;child.&nbsp;This&nbsp;feature&nbsp;is&nbsp;useful&nbsp;in<br>
371 conjunction&nbsp;with&nbsp;searchwindowsize.<br>
372 &nbsp;<br>
373 The&nbsp;searchwindowsize&nbsp;attribute&nbsp;sets&nbsp;the&nbsp;how&nbsp;far&nbsp;back&nbsp;in&nbsp;the&nbsp;incomming<br>
374 seach&nbsp;buffer&nbsp;Pexpect&nbsp;will&nbsp;search&nbsp;for&nbsp;pattern&nbsp;matches.&nbsp;Every&nbsp;time<br>
375 Pexpect&nbsp;reads&nbsp;some&nbsp;data&nbsp;from&nbsp;the&nbsp;child&nbsp;it&nbsp;will&nbsp;append&nbsp;the&nbsp;data&nbsp;to&nbsp;the<br>
376 incomming&nbsp;buffer.&nbsp;The&nbsp;default&nbsp;is&nbsp;to&nbsp;search&nbsp;from&nbsp;the&nbsp;beginning&nbsp;of&nbsp;the<br>
377 imcomming&nbsp;buffer&nbsp;each&nbsp;time&nbsp;new&nbsp;data&nbsp;is&nbsp;read&nbsp;from&nbsp;the&nbsp;child.&nbsp;But&nbsp;this&nbsp;is<br>
378 very&nbsp;inefficient&nbsp;if&nbsp;you&nbsp;are&nbsp;running&nbsp;a&nbsp;command&nbsp;that&nbsp;generates&nbsp;a&nbsp;large<br>
379 amount&nbsp;of&nbsp;data&nbsp;where&nbsp;you&nbsp;want&nbsp;to&nbsp;match&nbsp;The&nbsp;searchwindowsize&nbsp;does&nbsp;not<br>
380 effect&nbsp;the&nbsp;size&nbsp;of&nbsp;the&nbsp;incomming&nbsp;data&nbsp;buffer.&nbsp;You&nbsp;will&nbsp;still&nbsp;have<br>
381 access&nbsp;to&nbsp;the&nbsp;full&nbsp;buffer&nbsp;after&nbsp;<a href="#spawn-expect">expect</a>()&nbsp;returns.<br>
382 &nbsp;<br>
383 The&nbsp;logfile&nbsp;member&nbsp;turns&nbsp;on&nbsp;or&nbsp;off&nbsp;logging.&nbsp;All&nbsp;input&nbsp;and&nbsp;output&nbsp;will<br>
384 be&nbsp;copied&nbsp;to&nbsp;the&nbsp;given&nbsp;file&nbsp;<a href="__builtin__.html#object">object</a>.&nbsp;Set&nbsp;logfile&nbsp;to&nbsp;None&nbsp;to&nbsp;stop<br>
385 logging.&nbsp;This&nbsp;is&nbsp;the&nbsp;default.&nbsp;Set&nbsp;logfile&nbsp;to&nbsp;sys.stdout&nbsp;to&nbsp;echo<br>
386 everything&nbsp;to&nbsp;standard&nbsp;output.&nbsp;The&nbsp;logfile&nbsp;is&nbsp;flushed&nbsp;after&nbsp;each&nbsp;write.<br>
387 &nbsp;<br>
388 Example&nbsp;log&nbsp;input&nbsp;and&nbsp;output&nbsp;to&nbsp;a&nbsp;file::<br>
389 &nbsp;<br>
390 &nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>('some_command')<br>
391 &nbsp;&nbsp;&nbsp;&nbsp;fout&nbsp;=&nbsp;file('mylog.txt','w')<br>
392 &nbsp;&nbsp;&nbsp;&nbsp;child.logfile&nbsp;=&nbsp;fout<br>
393 &nbsp;<br>
394 Example&nbsp;log&nbsp;to&nbsp;stdout::<br>
395 &nbsp;<br>
396 &nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>('some_command')<br>
397 &nbsp;&nbsp;&nbsp;&nbsp;child.logfile&nbsp;=&nbsp;sys.stdout<br>
398 &nbsp;<br>
399 The&nbsp;logfile_read&nbsp;and&nbsp;logfile_send&nbsp;members&nbsp;can&nbsp;be&nbsp;used&nbsp;to&nbsp;separately&nbsp;log<br>
400 the&nbsp;input&nbsp;from&nbsp;the&nbsp;child&nbsp;and&nbsp;output&nbsp;sent&nbsp;to&nbsp;the&nbsp;child.&nbsp;Sometimes&nbsp;you<br>
401 don't&nbsp;want&nbsp;to&nbsp;see&nbsp;everything&nbsp;you&nbsp;write&nbsp;to&nbsp;the&nbsp;child.&nbsp;You&nbsp;only&nbsp;want&nbsp;to<br>
402 log&nbsp;what&nbsp;the&nbsp;child&nbsp;sends&nbsp;back.&nbsp;For&nbsp;example::<br>
403 &nbsp;<br>
404 &nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>('some_command')<br>
405 &nbsp;&nbsp;&nbsp;&nbsp;child.logfile_read&nbsp;=&nbsp;sys.stdout<br>
406 &nbsp;<br>
407 To&nbsp;separately&nbsp;log&nbsp;output&nbsp;sent&nbsp;to&nbsp;the&nbsp;child&nbsp;use&nbsp;logfile_send::<br>
408 &nbsp;<br>
409 &nbsp;&nbsp;&nbsp;&nbsp;self.<strong>logfile_send</strong>&nbsp;=&nbsp;fout<br>
410 &nbsp;<br>
411 The&nbsp;delaybeforesend&nbsp;helps&nbsp;overcome&nbsp;a&nbsp;weird&nbsp;behavior&nbsp;that&nbsp;many&nbsp;users<br>
412 were&nbsp;experiencing.&nbsp;The&nbsp;typical&nbsp;problem&nbsp;was&nbsp;that&nbsp;a&nbsp;user&nbsp;would&nbsp;<a href="#spawn-expect">expect</a>()&nbsp;a<br>
413 "Password:"&nbsp;prompt&nbsp;and&nbsp;then&nbsp;immediately&nbsp;call&nbsp;<a href="#spawn-sendline">sendline</a>()&nbsp;to&nbsp;send&nbsp;the<br>
414 password.&nbsp;The&nbsp;user&nbsp;would&nbsp;then&nbsp;see&nbsp;that&nbsp;their&nbsp;password&nbsp;was&nbsp;echoed&nbsp;back<br>
415 to&nbsp;them.&nbsp;Passwords&nbsp;don't&nbsp;normally&nbsp;echo.&nbsp;The&nbsp;problem&nbsp;is&nbsp;caused&nbsp;by&nbsp;the<br>
416 fact&nbsp;that&nbsp;most&nbsp;applications&nbsp;print&nbsp;out&nbsp;the&nbsp;"Password"&nbsp;prompt&nbsp;and&nbsp;then<br>
417 turn&nbsp;off&nbsp;stdin&nbsp;echo,&nbsp;but&nbsp;if&nbsp;you&nbsp;send&nbsp;your&nbsp;password&nbsp;before&nbsp;the<br>
418 application&nbsp;turned&nbsp;off&nbsp;echo,&nbsp;then&nbsp;you&nbsp;get&nbsp;your&nbsp;password&nbsp;echoed.<br>
419 Normally&nbsp;this&nbsp;wouldn't&nbsp;be&nbsp;a&nbsp;problem&nbsp;when&nbsp;interacting&nbsp;with&nbsp;a&nbsp;human&nbsp;at&nbsp;a<br>
420 real&nbsp;keyboard.&nbsp;If&nbsp;you&nbsp;introduce&nbsp;a&nbsp;slight&nbsp;delay&nbsp;just&nbsp;before&nbsp;writing&nbsp;then<br>
421 this&nbsp;seems&nbsp;to&nbsp;clear&nbsp;up&nbsp;the&nbsp;problem.&nbsp;This&nbsp;was&nbsp;such&nbsp;a&nbsp;common&nbsp;problem&nbsp;for<br>
422 many&nbsp;users&nbsp;that&nbsp;I&nbsp;decided&nbsp;that&nbsp;the&nbsp;default&nbsp;pexpect&nbsp;behavior&nbsp;should&nbsp;be<br>
423 to&nbsp;sleep&nbsp;just&nbsp;before&nbsp;writing&nbsp;to&nbsp;the&nbsp;child&nbsp;application.&nbsp;1/20th&nbsp;of&nbsp;a<br>
424 second&nbsp;(50&nbsp;ms)&nbsp;seems&nbsp;to&nbsp;be&nbsp;enough&nbsp;to&nbsp;clear&nbsp;up&nbsp;the&nbsp;problem.&nbsp;You&nbsp;can&nbsp;set<br>
425 delaybeforesend&nbsp;to&nbsp;0&nbsp;to&nbsp;return&nbsp;to&nbsp;the&nbsp;old&nbsp;behavior.&nbsp;Most&nbsp;Linux&nbsp;machines<br>
426 don't&nbsp;like&nbsp;this&nbsp;to&nbsp;be&nbsp;below&nbsp;0.03.&nbsp;I&nbsp;don't&nbsp;know&nbsp;why.<br>
427 &nbsp;<br>
428 Note&nbsp;that&nbsp;<a href="#spawn">spawn</a>&nbsp;is&nbsp;clever&nbsp;about&nbsp;finding&nbsp;commands&nbsp;on&nbsp;your&nbsp;path.<br>
429 It&nbsp;uses&nbsp;the&nbsp;same&nbsp;logic&nbsp;that&nbsp;"which"&nbsp;uses&nbsp;to&nbsp;find&nbsp;executables.<br>
430 &nbsp;<br>
431 If&nbsp;you&nbsp;wish&nbsp;to&nbsp;get&nbsp;the&nbsp;exit&nbsp;status&nbsp;of&nbsp;the&nbsp;child&nbsp;you&nbsp;must&nbsp;call&nbsp;the<br>
432 <a href="#spawn-close">close</a>()&nbsp;method.&nbsp;The&nbsp;exit&nbsp;or&nbsp;signal&nbsp;status&nbsp;of&nbsp;the&nbsp;child&nbsp;will&nbsp;be&nbsp;stored<br>
433 in&nbsp;self.<strong>exitstatus</strong>&nbsp;or&nbsp;self.<strong>signalstatus</strong>.&nbsp;If&nbsp;the&nbsp;child&nbsp;exited&nbsp;normally<br>
434 then&nbsp;exitstatus&nbsp;will&nbsp;store&nbsp;the&nbsp;exit&nbsp;return&nbsp;code&nbsp;and&nbsp;signalstatus&nbsp;will<br>
435 be&nbsp;None.&nbsp;If&nbsp;the&nbsp;child&nbsp;was&nbsp;terminated&nbsp;abnormally&nbsp;with&nbsp;a&nbsp;signal&nbsp;then<br>
436 signalstatus&nbsp;will&nbsp;store&nbsp;the&nbsp;signal&nbsp;value&nbsp;and&nbsp;exitstatus&nbsp;will&nbsp;be&nbsp;None.<br>
437 If&nbsp;you&nbsp;need&nbsp;more&nbsp;detail&nbsp;you&nbsp;can&nbsp;also&nbsp;read&nbsp;the&nbsp;self.<strong>status</strong>&nbsp;member&nbsp;which<br>
438 stores&nbsp;the&nbsp;status&nbsp;returned&nbsp;by&nbsp;os.waitpid.&nbsp;You&nbsp;can&nbsp;interpret&nbsp;this&nbsp;using<br>
439 os.WIFEXITED/os.WEXITSTATUS&nbsp;or&nbsp;os.WIFSIGNALED/os.TERMSIG.</tt></dd></dl>
440
441 <dl><dt><a name="spawn-__iter__"><strong>__iter__</strong></a>(self)</dt><dd><tt>This&nbsp;is&nbsp;to&nbsp;support&nbsp;iterators&nbsp;over&nbsp;a&nbsp;file-like&nbsp;<a href="__builtin__.html#object">object</a>.</tt></dd></dl>
442
443 <dl><dt><a name="spawn-__str__"><strong>__str__</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;a&nbsp;human-readable&nbsp;string&nbsp;that&nbsp;represents&nbsp;the&nbsp;state&nbsp;of<br>
444 the&nbsp;<a href="__builtin__.html#object">object</a>.</tt></dd></dl>
445
446 <dl><dt><a name="spawn-close"><strong>close</strong></a>(self, force<font color="#909090">=True</font>)</dt><dd><tt>This&nbsp;closes&nbsp;the&nbsp;connection&nbsp;with&nbsp;the&nbsp;child&nbsp;application.&nbsp;Note&nbsp;that<br>
447 calling&nbsp;<a href="#spawn-close">close</a>()&nbsp;more&nbsp;than&nbsp;once&nbsp;is&nbsp;valid.&nbsp;This&nbsp;emulates&nbsp;standard&nbsp;Python<br>
448 behavior&nbsp;with&nbsp;files.&nbsp;Set&nbsp;force&nbsp;to&nbsp;True&nbsp;if&nbsp;you&nbsp;want&nbsp;to&nbsp;make&nbsp;sure&nbsp;that<br>
449 the&nbsp;child&nbsp;is&nbsp;terminated&nbsp;(SIGKILL&nbsp;is&nbsp;sent&nbsp;if&nbsp;the&nbsp;child&nbsp;ignores&nbsp;SIGHUP<br>
450 and&nbsp;SIGINT).</tt></dd></dl>
451
452 <dl><dt><a name="spawn-compile_pattern_list"><strong>compile_pattern_list</strong></a>(self, patterns)</dt><dd><tt>This&nbsp;compiles&nbsp;a&nbsp;pattern-string&nbsp;or&nbsp;a&nbsp;list&nbsp;of&nbsp;pattern-strings.<br>
453 Patterns&nbsp;must&nbsp;be&nbsp;a&nbsp;StringType,&nbsp;<a href="#EOF">EOF</a>,&nbsp;<a href="#TIMEOUT">TIMEOUT</a>,&nbsp;SRE_Pattern,&nbsp;or&nbsp;a&nbsp;list&nbsp;of<br>
454 those.&nbsp;Patterns&nbsp;may&nbsp;also&nbsp;be&nbsp;None&nbsp;which&nbsp;results&nbsp;in&nbsp;an&nbsp;empty&nbsp;list&nbsp;(you<br>
455 might&nbsp;do&nbsp;this&nbsp;if&nbsp;waiting&nbsp;for&nbsp;an&nbsp;<a href="#EOF">EOF</a>&nbsp;or&nbsp;<a href="#TIMEOUT">TIMEOUT</a>&nbsp;condition&nbsp;without<br>
456 expecting&nbsp;any&nbsp;pattern).<br>
457 &nbsp;<br>
458 This&nbsp;is&nbsp;used&nbsp;by&nbsp;<a href="#spawn-expect">expect</a>()&nbsp;when&nbsp;calling&nbsp;<a href="#spawn-expect_list">expect_list</a>().&nbsp;Thus&nbsp;<a href="#spawn-expect">expect</a>()&nbsp;is<br>
459 nothing&nbsp;more&nbsp;than::<br>
460 &nbsp;<br>
461 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cpl&nbsp;=&nbsp;<a href="#spawn-compile_pattern_list">compile_pattern_list</a>(pl)<br>
462 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<a href="#spawn-expect_list">expect_list</a>(cpl,&nbsp;timeout)<br>
463 &nbsp;<br>
464 If&nbsp;you&nbsp;are&nbsp;using&nbsp;<a href="#spawn-expect">expect</a>()&nbsp;within&nbsp;a&nbsp;loop&nbsp;it&nbsp;may&nbsp;be&nbsp;more<br>
465 efficient&nbsp;to&nbsp;compile&nbsp;the&nbsp;patterns&nbsp;first&nbsp;and&nbsp;then&nbsp;call&nbsp;<a href="#spawn-expect_list">expect_list</a>().<br>
466 This&nbsp;avoid&nbsp;calls&nbsp;in&nbsp;a&nbsp;loop&nbsp;to&nbsp;<a href="#spawn-compile_pattern_list">compile_pattern_list</a>()::<br>
467 &nbsp;<br>
468 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cpl&nbsp;=&nbsp;<a href="#spawn-compile_pattern_list">compile_pattern_list</a>(my_pattern)<br>
469 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;some_condition:<br>
470 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...<br>
471 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i&nbsp;=&nbsp;<a href="#spawn-expect_list">expect_list</a>(clp,&nbsp;timeout)<br>
472 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...</tt></dd></dl>
473
474 <dl><dt><a name="spawn-eof"><strong>eof</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;True&nbsp;if&nbsp;the&nbsp;<a href="#EOF">EOF</a>&nbsp;exception&nbsp;was&nbsp;ever&nbsp;raised.</tt></dd></dl>
475
476 <dl><dt><a name="spawn-expect"><strong>expect</strong></a>(self, pattern, timeout<font color="#909090">=-1</font>, searchwindowsize<font color="#909090">=None</font>)</dt><dd><tt>This&nbsp;seeks&nbsp;through&nbsp;the&nbsp;stream&nbsp;until&nbsp;a&nbsp;pattern&nbsp;is&nbsp;matched.&nbsp;The<br>
477 pattern&nbsp;is&nbsp;overloaded&nbsp;and&nbsp;may&nbsp;take&nbsp;several&nbsp;types.&nbsp;The&nbsp;pattern&nbsp;can&nbsp;be&nbsp;a<br>
478 StringType,&nbsp;<a href="#EOF">EOF</a>,&nbsp;a&nbsp;compiled&nbsp;re,&nbsp;or&nbsp;a&nbsp;list&nbsp;of&nbsp;any&nbsp;of&nbsp;those&nbsp;types.<br>
479 Strings&nbsp;will&nbsp;be&nbsp;compiled&nbsp;to&nbsp;re&nbsp;types.&nbsp;This&nbsp;returns&nbsp;the&nbsp;index&nbsp;into&nbsp;the<br>
480 pattern&nbsp;list.&nbsp;If&nbsp;the&nbsp;pattern&nbsp;was&nbsp;not&nbsp;a&nbsp;list&nbsp;this&nbsp;returns&nbsp;index&nbsp;0&nbsp;on&nbsp;a<br>
481 successful&nbsp;match.&nbsp;This&nbsp;may&nbsp;raise&nbsp;exceptions&nbsp;for&nbsp;<a href="#EOF">EOF</a>&nbsp;or&nbsp;<a href="#TIMEOUT">TIMEOUT</a>.&nbsp;To<br>
482 avoid&nbsp;the&nbsp;<a href="#EOF">EOF</a>&nbsp;or&nbsp;<a href="#TIMEOUT">TIMEOUT</a>&nbsp;exceptions&nbsp;add&nbsp;<a href="#EOF">EOF</a>&nbsp;or&nbsp;<a href="#TIMEOUT">TIMEOUT</a>&nbsp;to&nbsp;the&nbsp;pattern<br>
483 list.&nbsp;That&nbsp;will&nbsp;cause&nbsp;expect&nbsp;to&nbsp;match&nbsp;an&nbsp;<a href="#EOF">EOF</a>&nbsp;or&nbsp;<a href="#TIMEOUT">TIMEOUT</a>&nbsp;condition<br>
484 instead&nbsp;of&nbsp;raising&nbsp;an&nbsp;exception.<br>
485 &nbsp;<br>
486 If&nbsp;you&nbsp;pass&nbsp;a&nbsp;list&nbsp;of&nbsp;patterns&nbsp;and&nbsp;more&nbsp;than&nbsp;one&nbsp;matches,&nbsp;the&nbsp;first&nbsp;match<br>
487 in&nbsp;the&nbsp;stream&nbsp;is&nbsp;chosen.&nbsp;If&nbsp;more&nbsp;than&nbsp;one&nbsp;pattern&nbsp;matches&nbsp;at&nbsp;that&nbsp;point,<br>
488 the&nbsp;leftmost&nbsp;in&nbsp;the&nbsp;pattern&nbsp;list&nbsp;is&nbsp;chosen.&nbsp;For&nbsp;example::<br>
489 &nbsp;<br>
490 &nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;the&nbsp;input&nbsp;is&nbsp;'foobar'<br>
491 &nbsp;&nbsp;&nbsp;&nbsp;index&nbsp;=&nbsp;p.expect&nbsp;(['bar',&nbsp;'foo',&nbsp;'foobar'])<br>
492 &nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;returns&nbsp;1&nbsp;('foo')&nbsp;even&nbsp;though&nbsp;'foobar'&nbsp;is&nbsp;a&nbsp;"better"&nbsp;match<br>
493 &nbsp;<br>
494 Please&nbsp;note,&nbsp;however,&nbsp;that&nbsp;buffering&nbsp;can&nbsp;affect&nbsp;this&nbsp;behavior,&nbsp;since<br>
495 input&nbsp;arrives&nbsp;in&nbsp;unpredictable&nbsp;chunks.&nbsp;For&nbsp;example::<br>
496 &nbsp;<br>
497 &nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;the&nbsp;input&nbsp;is&nbsp;'foobar'<br>
498 &nbsp;&nbsp;&nbsp;&nbsp;index&nbsp;=&nbsp;p.expect&nbsp;(['foobar',&nbsp;'foo'])<br>
499 &nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;returns&nbsp;0&nbsp;('foobar')&nbsp;if&nbsp;all&nbsp;input&nbsp;is&nbsp;available&nbsp;at&nbsp;once,<br>
500 &nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;but&nbsp;returs&nbsp;1&nbsp;('foo')&nbsp;if&nbsp;parts&nbsp;of&nbsp;the&nbsp;final&nbsp;'bar'&nbsp;arrive&nbsp;late<br>
501 &nbsp;<br>
502 After&nbsp;a&nbsp;match&nbsp;is&nbsp;found&nbsp;the&nbsp;instance&nbsp;attributes&nbsp;'before',&nbsp;'after'&nbsp;and<br>
503 'match'&nbsp;will&nbsp;be&nbsp;set.&nbsp;You&nbsp;can&nbsp;see&nbsp;all&nbsp;the&nbsp;data&nbsp;read&nbsp;before&nbsp;the&nbsp;match&nbsp;in<br>
504 'before'.&nbsp;You&nbsp;can&nbsp;see&nbsp;the&nbsp;data&nbsp;that&nbsp;was&nbsp;matched&nbsp;in&nbsp;'after'.&nbsp;The<br>
505 re.MatchObject&nbsp;used&nbsp;in&nbsp;the&nbsp;re&nbsp;match&nbsp;will&nbsp;be&nbsp;in&nbsp;'match'.&nbsp;If&nbsp;an&nbsp;error<br>
506 occurred&nbsp;then&nbsp;'before'&nbsp;will&nbsp;be&nbsp;set&nbsp;to&nbsp;all&nbsp;the&nbsp;data&nbsp;read&nbsp;so&nbsp;far&nbsp;and<br>
507 'after'&nbsp;and&nbsp;'match'&nbsp;will&nbsp;be&nbsp;None.<br>
508 &nbsp;<br>
509 If&nbsp;timeout&nbsp;is&nbsp;-1&nbsp;then&nbsp;timeout&nbsp;will&nbsp;be&nbsp;set&nbsp;to&nbsp;the&nbsp;self.<strong>timeout</strong>&nbsp;value.<br>
510 &nbsp;<br>
511 A&nbsp;list&nbsp;entry&nbsp;may&nbsp;be&nbsp;<a href="#EOF">EOF</a>&nbsp;or&nbsp;<a href="#TIMEOUT">TIMEOUT</a>&nbsp;instead&nbsp;of&nbsp;a&nbsp;string.&nbsp;This&nbsp;will<br>
512 catch&nbsp;these&nbsp;exceptions&nbsp;and&nbsp;return&nbsp;the&nbsp;index&nbsp;of&nbsp;the&nbsp;list&nbsp;entry&nbsp;instead<br>
513 of&nbsp;raising&nbsp;the&nbsp;exception.&nbsp;The&nbsp;attribute&nbsp;'after'&nbsp;will&nbsp;be&nbsp;set&nbsp;to&nbsp;the<br>
514 exception&nbsp;type.&nbsp;The&nbsp;attribute&nbsp;'match'&nbsp;will&nbsp;be&nbsp;None.&nbsp;This&nbsp;allows&nbsp;you&nbsp;to<br>
515 write&nbsp;code&nbsp;like&nbsp;this::<br>
516 &nbsp;<br>
517 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index&nbsp;=&nbsp;p.expect&nbsp;(['good',&nbsp;'bad',&nbsp;pexpect.<a href="#EOF">EOF</a>,&nbsp;pexpect.<a href="#TIMEOUT">TIMEOUT</a>])<br>
518 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;index&nbsp;==&nbsp;0:<br>
519 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_something()<br>
520 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif&nbsp;index&nbsp;==&nbsp;1:<br>
521 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_something_else()<br>
522 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif&nbsp;index&nbsp;==&nbsp;2:<br>
523 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_some_other_thing()<br>
524 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif&nbsp;index&nbsp;==&nbsp;3:<br>
525 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_something_completely_different()<br>
526 &nbsp;<br>
527 instead&nbsp;of&nbsp;code&nbsp;like&nbsp;this::<br>
528 &nbsp;<br>
529 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try:<br>
530 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index&nbsp;=&nbsp;p.expect&nbsp;(['good',&nbsp;'bad'])<br>
531 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;index&nbsp;==&nbsp;0:<br>
532 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_something()<br>
533 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif&nbsp;index&nbsp;==&nbsp;1:<br>
534 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_something_else()<br>
535 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;except&nbsp;<a href="#EOF">EOF</a>:<br>
536 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_some_other_thing()<br>
537 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;except&nbsp;<a href="#TIMEOUT">TIMEOUT</a>:<br>
538 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_something_completely_different()<br>
539 &nbsp;<br>
540 These&nbsp;two&nbsp;forms&nbsp;are&nbsp;equivalent.&nbsp;It&nbsp;all&nbsp;depends&nbsp;on&nbsp;what&nbsp;you&nbsp;want.&nbsp;You<br>
541 can&nbsp;also&nbsp;just&nbsp;expect&nbsp;the&nbsp;<a href="#EOF">EOF</a>&nbsp;if&nbsp;you&nbsp;are&nbsp;waiting&nbsp;for&nbsp;all&nbsp;output&nbsp;of&nbsp;a<br>
542 child&nbsp;to&nbsp;finish.&nbsp;For&nbsp;example::<br>
543 &nbsp;<br>
544 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>('/bin/ls')<br>
545 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(pexpect.<a href="#EOF">EOF</a>)<br>
546 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;p.before<br>
547 &nbsp;<br>
548 If&nbsp;you&nbsp;are&nbsp;trying&nbsp;to&nbsp;optimize&nbsp;for&nbsp;speed&nbsp;then&nbsp;see&nbsp;<a href="#spawn-expect_list">expect_list</a>().</tt></dd></dl>
549
550 <dl><dt><a name="spawn-expect_exact"><strong>expect_exact</strong></a>(self, pattern_list, timeout<font color="#909090">=-1</font>, searchwindowsize<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;is&nbsp;similar&nbsp;to&nbsp;<a href="#spawn-expect">expect</a>(),&nbsp;but&nbsp;uses&nbsp;plain&nbsp;string&nbsp;matching&nbsp;instead<br>
551 of&nbsp;compiled&nbsp;regular&nbsp;expressions&nbsp;in&nbsp;'pattern_list'.&nbsp;The&nbsp;'pattern_list'<br>
552 may&nbsp;be&nbsp;a&nbsp;string;&nbsp;a&nbsp;list&nbsp;or&nbsp;other&nbsp;sequence&nbsp;of&nbsp;strings;&nbsp;or&nbsp;<a href="#TIMEOUT">TIMEOUT</a>&nbsp;and<br>
553 <a href="#EOF">EOF</a>.<br>
554 &nbsp;<br>
555 This&nbsp;call&nbsp;might&nbsp;be&nbsp;faster&nbsp;than&nbsp;<a href="#spawn-expect">expect</a>()&nbsp;for&nbsp;two&nbsp;reasons:&nbsp;string<br>
556 searching&nbsp;is&nbsp;faster&nbsp;than&nbsp;RE&nbsp;matching&nbsp;and&nbsp;it&nbsp;is&nbsp;possible&nbsp;to&nbsp;limit&nbsp;the<br>
557 search&nbsp;to&nbsp;just&nbsp;the&nbsp;end&nbsp;of&nbsp;the&nbsp;input&nbsp;buffer.<br>
558 &nbsp;<br>
559 This&nbsp;method&nbsp;is&nbsp;also&nbsp;useful&nbsp;when&nbsp;you&nbsp;don't&nbsp;want&nbsp;to&nbsp;have&nbsp;to&nbsp;worry&nbsp;about<br>
560 escaping&nbsp;regular&nbsp;expression&nbsp;characters&nbsp;that&nbsp;you&nbsp;want&nbsp;to&nbsp;match.</tt></dd></dl>
561
562 <dl><dt><a name="spawn-expect_list"><strong>expect_list</strong></a>(self, pattern_list, timeout<font color="#909090">=-1</font>, searchwindowsize<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;takes&nbsp;a&nbsp;list&nbsp;of&nbsp;compiled&nbsp;regular&nbsp;expressions&nbsp;and&nbsp;returns&nbsp;the<br>
563 index&nbsp;into&nbsp;the&nbsp;pattern_list&nbsp;that&nbsp;matched&nbsp;the&nbsp;child&nbsp;output.&nbsp;The&nbsp;list&nbsp;may<br>
564 also&nbsp;contain&nbsp;<a href="#EOF">EOF</a>&nbsp;or&nbsp;<a href="#TIMEOUT">TIMEOUT</a>&nbsp;(which&nbsp;are&nbsp;not&nbsp;compiled&nbsp;regular<br>
565 expressions).&nbsp;This&nbsp;method&nbsp;is&nbsp;similar&nbsp;to&nbsp;the&nbsp;<a href="#spawn-expect">expect</a>()&nbsp;method&nbsp;except&nbsp;that<br>
566 <a href="#spawn-expect_list">expect_list</a>()&nbsp;does&nbsp;not&nbsp;recompile&nbsp;the&nbsp;pattern&nbsp;list&nbsp;on&nbsp;every&nbsp;call.&nbsp;This<br>
567 may&nbsp;help&nbsp;if&nbsp;you&nbsp;are&nbsp;trying&nbsp;to&nbsp;optimize&nbsp;for&nbsp;speed,&nbsp;otherwise&nbsp;just&nbsp;use<br>
568 the&nbsp;<a href="#spawn-expect">expect</a>()&nbsp;method.&nbsp;&nbsp;This&nbsp;is&nbsp;called&nbsp;by&nbsp;<a href="#spawn-expect">expect</a>().&nbsp;If&nbsp;timeout==-1&nbsp;then<br>
569 the&nbsp;self.<strong>timeout</strong>&nbsp;value&nbsp;is&nbsp;used.&nbsp;If&nbsp;searchwindowsize==-1&nbsp;then&nbsp;the<br>
570 self.<strong>searchwindowsize</strong>&nbsp;value&nbsp;is&nbsp;used.</tt></dd></dl>
571
572 <dl><dt><a name="spawn-expect_loop"><strong>expect_loop</strong></a>(self, searcher, timeout<font color="#909090">=-1</font>, searchwindowsize<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;is&nbsp;the&nbsp;common&nbsp;loop&nbsp;used&nbsp;inside&nbsp;expect.&nbsp;The&nbsp;'searcher'&nbsp;should&nbsp;be<br>
573 an&nbsp;instance&nbsp;of&nbsp;searcher_re&nbsp;or&nbsp;searcher_string,&nbsp;which&nbsp;describes&nbsp;how&nbsp;and&nbsp;what<br>
574 to&nbsp;search&nbsp;for&nbsp;in&nbsp;the&nbsp;input.<br>
575 &nbsp;<br>
576 See&nbsp;<a href="#spawn-expect">expect</a>()&nbsp;for&nbsp;other&nbsp;arguments,&nbsp;return&nbsp;value&nbsp;and&nbsp;exceptions.</tt></dd></dl>
577
578 <dl><dt><a name="spawn-fileno"><strong>fileno</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;the&nbsp;file&nbsp;descriptor&nbsp;of&nbsp;the&nbsp;pty&nbsp;for&nbsp;the&nbsp;child.</tt></dd></dl>
579
580 <dl><dt><a name="spawn-flush"><strong>flush</strong></a>(self)</dt><dd><tt>This&nbsp;does&nbsp;nothing.&nbsp;It&nbsp;is&nbsp;here&nbsp;to&nbsp;support&nbsp;the&nbsp;interface&nbsp;for&nbsp;a<br>
581 File-like&nbsp;<a href="__builtin__.html#object">object</a>.</tt></dd></dl>
582
583 <dl><dt><a name="spawn-getecho"><strong>getecho</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;the&nbsp;terminal&nbsp;echo&nbsp;mode.&nbsp;This&nbsp;returns&nbsp;True&nbsp;if&nbsp;echo&nbsp;is<br>
584 on&nbsp;or&nbsp;False&nbsp;if&nbsp;echo&nbsp;is&nbsp;off.&nbsp;Child&nbsp;applications&nbsp;that&nbsp;are&nbsp;expecting&nbsp;you<br>
585 to&nbsp;enter&nbsp;a&nbsp;password&nbsp;often&nbsp;set&nbsp;ECHO&nbsp;False.&nbsp;See&nbsp;<a href="#spawn-waitnoecho">waitnoecho</a>().</tt></dd></dl>
586
587 <dl><dt><a name="spawn-getwinsize"><strong>getwinsize</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;the&nbsp;terminal&nbsp;window&nbsp;size&nbsp;of&nbsp;the&nbsp;child&nbsp;tty.&nbsp;The&nbsp;return<br>
588 value&nbsp;is&nbsp;a&nbsp;tuple&nbsp;of&nbsp;(rows,&nbsp;cols).</tt></dd></dl>
589
590 <dl><dt><a name="spawn-interact"><strong>interact</strong></a>(self, escape_character<font color="#909090">='<font color="#c040c0">\x1d</font>'</font>, input_filter<font color="#909090">=None</font>, output_filter<font color="#909090">=None</font>)</dt><dd><tt>This&nbsp;gives&nbsp;control&nbsp;of&nbsp;the&nbsp;child&nbsp;process&nbsp;to&nbsp;the&nbsp;interactive&nbsp;user&nbsp;(the<br>
591 human&nbsp;at&nbsp;the&nbsp;keyboard).&nbsp;Keystrokes&nbsp;are&nbsp;sent&nbsp;to&nbsp;the&nbsp;child&nbsp;process,&nbsp;and<br>
592 the&nbsp;stdout&nbsp;and&nbsp;stderr&nbsp;output&nbsp;of&nbsp;the&nbsp;child&nbsp;process&nbsp;is&nbsp;printed.&nbsp;This<br>
593 simply&nbsp;echos&nbsp;the&nbsp;child&nbsp;stdout&nbsp;and&nbsp;child&nbsp;stderr&nbsp;to&nbsp;the&nbsp;real&nbsp;stdout&nbsp;and<br>
594 it&nbsp;echos&nbsp;the&nbsp;real&nbsp;stdin&nbsp;to&nbsp;the&nbsp;child&nbsp;stdin.&nbsp;When&nbsp;the&nbsp;user&nbsp;types&nbsp;the<br>
595 escape_character&nbsp;this&nbsp;method&nbsp;will&nbsp;stop.&nbsp;The&nbsp;default&nbsp;for<br>
596 escape_character&nbsp;is&nbsp;^].&nbsp;This&nbsp;should&nbsp;not&nbsp;be&nbsp;confused&nbsp;with&nbsp;ASCII&nbsp;27&nbsp;--<br>
597 the&nbsp;ESC&nbsp;character.&nbsp;ASCII&nbsp;29&nbsp;was&nbsp;chosen&nbsp;for&nbsp;historical&nbsp;merit&nbsp;because<br>
598 this&nbsp;is&nbsp;the&nbsp;character&nbsp;used&nbsp;by&nbsp;'telnet'&nbsp;as&nbsp;the&nbsp;escape&nbsp;character.&nbsp;The<br>
599 escape_character&nbsp;will&nbsp;not&nbsp;be&nbsp;sent&nbsp;to&nbsp;the&nbsp;child&nbsp;process.<br>
600 &nbsp;<br>
601 You&nbsp;may&nbsp;pass&nbsp;in&nbsp;optional&nbsp;input&nbsp;and&nbsp;output&nbsp;filter&nbsp;functions.&nbsp;These<br>
602 functions&nbsp;should&nbsp;take&nbsp;a&nbsp;string&nbsp;and&nbsp;return&nbsp;a&nbsp;string.&nbsp;The&nbsp;output_filter<br>
603 will&nbsp;be&nbsp;passed&nbsp;all&nbsp;the&nbsp;output&nbsp;from&nbsp;the&nbsp;child&nbsp;process.&nbsp;The&nbsp;input_filter<br>
604 will&nbsp;be&nbsp;passed&nbsp;all&nbsp;the&nbsp;keyboard&nbsp;input&nbsp;from&nbsp;the&nbsp;user.&nbsp;The&nbsp;input_filter<br>
605 is&nbsp;run&nbsp;BEFORE&nbsp;the&nbsp;check&nbsp;for&nbsp;the&nbsp;escape_character.<br>
606 &nbsp;<br>
607 Note&nbsp;that&nbsp;if&nbsp;you&nbsp;change&nbsp;the&nbsp;window&nbsp;size&nbsp;of&nbsp;the&nbsp;parent&nbsp;the&nbsp;SIGWINCH<br>
608 signal&nbsp;will&nbsp;not&nbsp;be&nbsp;passed&nbsp;through&nbsp;to&nbsp;the&nbsp;child.&nbsp;If&nbsp;you&nbsp;want&nbsp;the&nbsp;child<br>
609 window&nbsp;size&nbsp;to&nbsp;change&nbsp;when&nbsp;the&nbsp;parent's&nbsp;window&nbsp;size&nbsp;changes&nbsp;then&nbsp;do<br>
610 something&nbsp;like&nbsp;the&nbsp;following&nbsp;example::<br>
611 &nbsp;<br>
612 &nbsp;&nbsp;&nbsp;&nbsp;import&nbsp;pexpect,&nbsp;struct,&nbsp;fcntl,&nbsp;termios,&nbsp;signal,&nbsp;sys<br>
613 &nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;sigwinch_passthrough&nbsp;(sig,&nbsp;data):<br>
614 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;=&nbsp;struct.pack("HHHH",&nbsp;0,&nbsp;0,&nbsp;0,&nbsp;0)<br>
615 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;=&nbsp;struct.unpack('hhhh',&nbsp;fcntl.ioctl(sys.stdout.<a href="#spawn-fileno">fileno</a>(),&nbsp;termios.TIOCGWINSZ&nbsp;,&nbsp;s))<br>
616 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;global&nbsp;p<br>
617 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p.<a href="#spawn-setwinsize">setwinsize</a>(a[0],a[1])<br>
618 &nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>('/bin/bash')&nbsp;#&nbsp;Note&nbsp;this&nbsp;is&nbsp;global&nbsp;and&nbsp;used&nbsp;in&nbsp;sigwinch_passthrough.<br>
619 &nbsp;&nbsp;&nbsp;&nbsp;signal.signal(signal.SIGWINCH,&nbsp;sigwinch_passthrough)<br>
620 &nbsp;&nbsp;&nbsp;&nbsp;p.<a href="#spawn-interact">interact</a>()</tt></dd></dl>
621
622 <dl><dt><a name="spawn-isalive"><strong>isalive</strong></a>(self)</dt><dd><tt>This&nbsp;tests&nbsp;if&nbsp;the&nbsp;child&nbsp;process&nbsp;is&nbsp;running&nbsp;or&nbsp;not.&nbsp;This&nbsp;is<br>
623 non-blocking.&nbsp;If&nbsp;the&nbsp;child&nbsp;was&nbsp;terminated&nbsp;then&nbsp;this&nbsp;will&nbsp;read&nbsp;the<br>
624 exitstatus&nbsp;or&nbsp;signalstatus&nbsp;of&nbsp;the&nbsp;child.&nbsp;This&nbsp;returns&nbsp;True&nbsp;if&nbsp;the&nbsp;child<br>
625 process&nbsp;appears&nbsp;to&nbsp;be&nbsp;running&nbsp;or&nbsp;False&nbsp;if&nbsp;not.&nbsp;It&nbsp;can&nbsp;take&nbsp;literally<br>
626 SECONDS&nbsp;for&nbsp;Solaris&nbsp;to&nbsp;return&nbsp;the&nbsp;right&nbsp;status.</tt></dd></dl>
627
628 <dl><dt><a name="spawn-isatty"><strong>isatty</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;True&nbsp;if&nbsp;the&nbsp;file&nbsp;descriptor&nbsp;is&nbsp;open&nbsp;and&nbsp;connected&nbsp;to&nbsp;a<br>
629 tty(-like)&nbsp;device,&nbsp;else&nbsp;False.</tt></dd></dl>
630
631 <dl><dt><a name="spawn-kill"><strong>kill</strong></a>(self, sig)</dt><dd><tt>This&nbsp;sends&nbsp;the&nbsp;given&nbsp;signal&nbsp;to&nbsp;the&nbsp;child&nbsp;application.&nbsp;In&nbsp;keeping<br>
632 with&nbsp;UNIX&nbsp;tradition&nbsp;it&nbsp;has&nbsp;a&nbsp;misleading&nbsp;name.&nbsp;It&nbsp;does&nbsp;not&nbsp;necessarily<br>
633 kill&nbsp;the&nbsp;child&nbsp;unless&nbsp;you&nbsp;send&nbsp;the&nbsp;right&nbsp;signal.</tt></dd></dl>
634
635 <dl><dt><a name="spawn-next"><strong>next</strong></a>(self)</dt><dd><tt>This&nbsp;is&nbsp;to&nbsp;support&nbsp;iterators&nbsp;over&nbsp;a&nbsp;file-like&nbsp;<a href="__builtin__.html#object">object</a>.</tt></dd></dl>
636
637 <dl><dt><a name="spawn-read"><strong>read</strong></a>(self, size<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;reads&nbsp;at&nbsp;most&nbsp;"size"&nbsp;bytes&nbsp;from&nbsp;the&nbsp;file&nbsp;(less&nbsp;if&nbsp;the&nbsp;read&nbsp;hits<br>
638 <a href="#EOF">EOF</a>&nbsp;before&nbsp;obtaining&nbsp;size&nbsp;bytes).&nbsp;If&nbsp;the&nbsp;size&nbsp;argument&nbsp;is&nbsp;negative&nbsp;or<br>
639 omitted,&nbsp;read&nbsp;all&nbsp;data&nbsp;until&nbsp;<a href="#EOF">EOF</a>&nbsp;is&nbsp;reached.&nbsp;The&nbsp;bytes&nbsp;are&nbsp;returned&nbsp;as<br>
640 a&nbsp;string&nbsp;<a href="__builtin__.html#object">object</a>.&nbsp;An&nbsp;empty&nbsp;string&nbsp;is&nbsp;returned&nbsp;when&nbsp;<a href="#EOF">EOF</a>&nbsp;is&nbsp;encountered<br>
641 immediately.</tt></dd></dl>
642
643 <dl><dt><a name="spawn-read_nonblocking"><strong>read_nonblocking</strong></a>(self, size<font color="#909090">=1</font>, timeout<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;reads&nbsp;at&nbsp;most&nbsp;size&nbsp;characters&nbsp;from&nbsp;the&nbsp;child&nbsp;application.&nbsp;It<br>
644 includes&nbsp;a&nbsp;timeout.&nbsp;If&nbsp;the&nbsp;read&nbsp;does&nbsp;not&nbsp;complete&nbsp;within&nbsp;the&nbsp;timeout<br>
645 period&nbsp;then&nbsp;a&nbsp;<a href="#TIMEOUT">TIMEOUT</a>&nbsp;exception&nbsp;is&nbsp;raised.&nbsp;If&nbsp;the&nbsp;end&nbsp;of&nbsp;file&nbsp;is&nbsp;read<br>
646 then&nbsp;an&nbsp;<a href="#EOF">EOF</a>&nbsp;exception&nbsp;will&nbsp;be&nbsp;raised.&nbsp;If&nbsp;a&nbsp;log&nbsp;file&nbsp;was&nbsp;set&nbsp;using<br>
647 <a href="#spawn-setlog">setlog</a>()&nbsp;then&nbsp;all&nbsp;data&nbsp;will&nbsp;also&nbsp;be&nbsp;written&nbsp;to&nbsp;the&nbsp;log&nbsp;file.<br>
648 &nbsp;<br>
649 If&nbsp;timeout&nbsp;is&nbsp;None&nbsp;then&nbsp;the&nbsp;read&nbsp;may&nbsp;block&nbsp;indefinitely.&nbsp;If&nbsp;timeout&nbsp;is&nbsp;-1<br>
650 then&nbsp;the&nbsp;self.<strong>timeout</strong>&nbsp;value&nbsp;is&nbsp;used.&nbsp;If&nbsp;timeout&nbsp;is&nbsp;0&nbsp;then&nbsp;the&nbsp;child&nbsp;is<br>
651 polled&nbsp;and&nbsp;if&nbsp;there&nbsp;was&nbsp;no&nbsp;data&nbsp;immediately&nbsp;ready&nbsp;then&nbsp;this&nbsp;will&nbsp;raise<br>
652 a&nbsp;<a href="#TIMEOUT">TIMEOUT</a>&nbsp;exception.<br>
653 &nbsp;<br>
654 The&nbsp;timeout&nbsp;refers&nbsp;only&nbsp;to&nbsp;the&nbsp;amount&nbsp;of&nbsp;time&nbsp;to&nbsp;read&nbsp;at&nbsp;least&nbsp;one<br>
655 character.&nbsp;This&nbsp;is&nbsp;not&nbsp;effected&nbsp;by&nbsp;the&nbsp;'size'&nbsp;parameter,&nbsp;so&nbsp;if&nbsp;you&nbsp;call<br>
656 <a href="#spawn-read_nonblocking">read_nonblocking</a>(size=100,&nbsp;timeout=30)&nbsp;and&nbsp;only&nbsp;one&nbsp;character&nbsp;is<br>
657 available&nbsp;right&nbsp;away&nbsp;then&nbsp;one&nbsp;character&nbsp;will&nbsp;be&nbsp;returned&nbsp;immediately.<br>
658 It&nbsp;will&nbsp;not&nbsp;wait&nbsp;for&nbsp;30&nbsp;seconds&nbsp;for&nbsp;another&nbsp;99&nbsp;characters&nbsp;to&nbsp;come&nbsp;in.<br>
659 &nbsp;<br>
660 This&nbsp;is&nbsp;a&nbsp;wrapper&nbsp;around&nbsp;os.<a href="#spawn-read">read</a>().&nbsp;It&nbsp;uses&nbsp;select.select()&nbsp;to<br>
661 implement&nbsp;the&nbsp;timeout.</tt></dd></dl>
662
663 <dl><dt><a name="spawn-readline"><strong>readline</strong></a>(self, size<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;reads&nbsp;and&nbsp;returns&nbsp;one&nbsp;entire&nbsp;line.&nbsp;A&nbsp;trailing&nbsp;newline&nbsp;is&nbsp;kept<br>
664 in&nbsp;the&nbsp;string,&nbsp;but&nbsp;may&nbsp;be&nbsp;absent&nbsp;when&nbsp;a&nbsp;file&nbsp;ends&nbsp;with&nbsp;an&nbsp;incomplete<br>
665 line.&nbsp;Note:&nbsp;This&nbsp;<a href="#spawn-readline">readline</a>()&nbsp;looks&nbsp;for&nbsp;a&nbsp;\r\n&nbsp;pair&nbsp;even&nbsp;on&nbsp;UNIX<br>
666 because&nbsp;this&nbsp;is&nbsp;what&nbsp;the&nbsp;pseudo&nbsp;tty&nbsp;device&nbsp;returns.&nbsp;So&nbsp;contrary&nbsp;to&nbsp;what<br>
667 you&nbsp;may&nbsp;expect&nbsp;you&nbsp;will&nbsp;receive&nbsp;the&nbsp;newline&nbsp;as&nbsp;\r\n.&nbsp;An&nbsp;empty&nbsp;string<br>
668 is&nbsp;returned&nbsp;when&nbsp;<a href="#EOF">EOF</a>&nbsp;is&nbsp;hit&nbsp;immediately.&nbsp;Currently,&nbsp;the&nbsp;size&nbsp;argument&nbsp;is<br>
669 mostly&nbsp;ignored,&nbsp;so&nbsp;this&nbsp;behavior&nbsp;is&nbsp;not&nbsp;standard&nbsp;for&nbsp;a&nbsp;file-like<br>
670 <a href="__builtin__.html#object">object</a>.&nbsp;If&nbsp;size&nbsp;is&nbsp;0&nbsp;then&nbsp;an&nbsp;empty&nbsp;string&nbsp;is&nbsp;returned.</tt></dd></dl>
671
672 <dl><dt><a name="spawn-readlines"><strong>readlines</strong></a>(self, sizehint<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;reads&nbsp;until&nbsp;<a href="#EOF">EOF</a>&nbsp;using&nbsp;<a href="#spawn-readline">readline</a>()&nbsp;and&nbsp;returns&nbsp;a&nbsp;list&nbsp;containing<br>
673 the&nbsp;lines&nbsp;thus&nbsp;read.&nbsp;The&nbsp;optional&nbsp;"sizehint"&nbsp;argument&nbsp;is&nbsp;ignored.</tt></dd></dl>
674
675 <dl><dt><a name="spawn-send"><strong>send</strong></a>(self, s)</dt><dd><tt>This&nbsp;sends&nbsp;a&nbsp;string&nbsp;to&nbsp;the&nbsp;child&nbsp;process.&nbsp;This&nbsp;returns&nbsp;the&nbsp;number&nbsp;of<br>
676 bytes&nbsp;written.&nbsp;If&nbsp;a&nbsp;log&nbsp;file&nbsp;was&nbsp;set&nbsp;then&nbsp;the&nbsp;data&nbsp;is&nbsp;also&nbsp;written&nbsp;to<br>
677 the&nbsp;log.</tt></dd></dl>
678
679 <dl><dt><a name="spawn-sendcontrol"><strong>sendcontrol</strong></a>(self, char)</dt><dd><tt>This&nbsp;sends&nbsp;a&nbsp;control&nbsp;character&nbsp;to&nbsp;the&nbsp;child&nbsp;such&nbsp;as&nbsp;Ctrl-C&nbsp;or<br>
680 Ctrl-D.&nbsp;For&nbsp;example,&nbsp;to&nbsp;send&nbsp;a&nbsp;Ctrl-G&nbsp;(ASCII&nbsp;7)::<br>
681 &nbsp;<br>
682 &nbsp;&nbsp;&nbsp;&nbsp;child.<a href="#spawn-sendcontrol">sendcontrol</a>('g')<br>
683 &nbsp;<br>
684 See&nbsp;also,&nbsp;<a href="#spawn-sendintr">sendintr</a>()&nbsp;and&nbsp;<a href="#spawn-sendeof">sendeof</a>().</tt></dd></dl>
685
686 <dl><dt><a name="spawn-sendeof"><strong>sendeof</strong></a>(self)</dt><dd><tt>This&nbsp;sends&nbsp;an&nbsp;<a href="#EOF">EOF</a>&nbsp;to&nbsp;the&nbsp;child.&nbsp;This&nbsp;sends&nbsp;a&nbsp;character&nbsp;which&nbsp;causes<br>
687 the&nbsp;pending&nbsp;parent&nbsp;output&nbsp;buffer&nbsp;to&nbsp;be&nbsp;sent&nbsp;to&nbsp;the&nbsp;waiting&nbsp;child<br>
688 program&nbsp;without&nbsp;waiting&nbsp;for&nbsp;end-of-line.&nbsp;If&nbsp;it&nbsp;is&nbsp;the&nbsp;first&nbsp;character<br>
689 of&nbsp;the&nbsp;line,&nbsp;the&nbsp;<a href="#spawn-read">read</a>()&nbsp;in&nbsp;the&nbsp;user&nbsp;program&nbsp;returns&nbsp;0,&nbsp;which&nbsp;signifies<br>
690 end-of-file.&nbsp;This&nbsp;means&nbsp;to&nbsp;work&nbsp;as&nbsp;expected&nbsp;a&nbsp;<a href="#spawn-sendeof">sendeof</a>()&nbsp;has&nbsp;to&nbsp;be<br>
691 called&nbsp;at&nbsp;the&nbsp;beginning&nbsp;of&nbsp;a&nbsp;line.&nbsp;This&nbsp;method&nbsp;does&nbsp;not&nbsp;send&nbsp;a&nbsp;newline.<br>
692 It&nbsp;is&nbsp;the&nbsp;responsibility&nbsp;of&nbsp;the&nbsp;caller&nbsp;to&nbsp;ensure&nbsp;the&nbsp;eof&nbsp;is&nbsp;sent&nbsp;at&nbsp;the<br>
693 beginning&nbsp;of&nbsp;a&nbsp;line.</tt></dd></dl>
694
695 <dl><dt><a name="spawn-sendintr"><strong>sendintr</strong></a>(self)</dt><dd><tt>This&nbsp;sends&nbsp;a&nbsp;SIGINT&nbsp;to&nbsp;the&nbsp;child.&nbsp;It&nbsp;does&nbsp;not&nbsp;require<br>
696 the&nbsp;SIGINT&nbsp;to&nbsp;be&nbsp;the&nbsp;first&nbsp;character&nbsp;on&nbsp;a&nbsp;line.</tt></dd></dl>
697
698 <dl><dt><a name="spawn-sendline"><strong>sendline</strong></a>(self, s<font color="#909090">=''</font>)</dt><dd><tt>This&nbsp;is&nbsp;like&nbsp;<a href="#spawn-send">send</a>(),&nbsp;but&nbsp;it&nbsp;adds&nbsp;a&nbsp;line&nbsp;feed&nbsp;(os.linesep).&nbsp;This<br>
699 returns&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;written.</tt></dd></dl>
700
701 <dl><dt><a name="spawn-setecho"><strong>setecho</strong></a>(self, state)</dt><dd><tt>This&nbsp;sets&nbsp;the&nbsp;terminal&nbsp;echo&nbsp;mode&nbsp;on&nbsp;or&nbsp;off.&nbsp;Note&nbsp;that&nbsp;anything&nbsp;the<br>
702 child&nbsp;sent&nbsp;before&nbsp;the&nbsp;echo&nbsp;will&nbsp;be&nbsp;lost,&nbsp;so&nbsp;you&nbsp;should&nbsp;be&nbsp;sure&nbsp;that<br>
703 your&nbsp;input&nbsp;buffer&nbsp;is&nbsp;empty&nbsp;before&nbsp;you&nbsp;call&nbsp;<a href="#spawn-setecho">setecho</a>().&nbsp;For&nbsp;example,&nbsp;the<br>
704 following&nbsp;will&nbsp;work&nbsp;as&nbsp;expected::<br>
705 &nbsp;<br>
706 &nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>('cat')<br>
707 &nbsp;&nbsp;&nbsp;&nbsp;p.sendline&nbsp;('1234')&nbsp;#&nbsp;We&nbsp;will&nbsp;see&nbsp;this&nbsp;twice&nbsp;(once&nbsp;from&nbsp;tty&nbsp;echo&nbsp;and&nbsp;again&nbsp;from&nbsp;cat).<br>
708 &nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['1234'])<br>
709 &nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['1234'])<br>
710 &nbsp;&nbsp;&nbsp;&nbsp;p.<a href="#spawn-setecho">setecho</a>(False)&nbsp;#&nbsp;Turn&nbsp;off&nbsp;tty&nbsp;echo<br>
711 &nbsp;&nbsp;&nbsp;&nbsp;p.sendline&nbsp;('abcd')&nbsp;#&nbsp;We&nbsp;will&nbsp;set&nbsp;this&nbsp;only&nbsp;once&nbsp;(echoed&nbsp;by&nbsp;cat).<br>
712 &nbsp;&nbsp;&nbsp;&nbsp;p.sendline&nbsp;('wxyz')&nbsp;#&nbsp;We&nbsp;will&nbsp;set&nbsp;this&nbsp;only&nbsp;once&nbsp;(echoed&nbsp;by&nbsp;cat)<br>
713 &nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['abcd'])<br>
714 &nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['wxyz'])<br>
715 &nbsp;<br>
716 The&nbsp;following&nbsp;WILL&nbsp;NOT&nbsp;WORK&nbsp;because&nbsp;the&nbsp;lines&nbsp;sent&nbsp;before&nbsp;the&nbsp;setecho<br>
717 will&nbsp;be&nbsp;lost::<br>
718 &nbsp;<br>
719 &nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>('cat')<br>
720 &nbsp;&nbsp;&nbsp;&nbsp;p.sendline&nbsp;('1234')&nbsp;#&nbsp;We&nbsp;will&nbsp;see&nbsp;this&nbsp;twice&nbsp;(once&nbsp;from&nbsp;tty&nbsp;echo&nbsp;and&nbsp;again&nbsp;from&nbsp;cat).<br>
721 &nbsp;&nbsp;&nbsp;&nbsp;p.<a href="#spawn-setecho">setecho</a>(False)&nbsp;#&nbsp;Turn&nbsp;off&nbsp;tty&nbsp;echo<br>
722 &nbsp;&nbsp;&nbsp;&nbsp;p.sendline&nbsp;('abcd')&nbsp;#&nbsp;We&nbsp;will&nbsp;set&nbsp;this&nbsp;only&nbsp;once&nbsp;(echoed&nbsp;by&nbsp;cat).<br>
723 &nbsp;&nbsp;&nbsp;&nbsp;p.sendline&nbsp;('wxyz')&nbsp;#&nbsp;We&nbsp;will&nbsp;set&nbsp;this&nbsp;only&nbsp;once&nbsp;(echoed&nbsp;by&nbsp;cat)<br>
724 &nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['1234'])<br>
725 &nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['1234'])<br>
726 &nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['abcd'])<br>
727 &nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['wxyz'])</tt></dd></dl>
728
729 <dl><dt><a name="spawn-setlog"><strong>setlog</strong></a>(self, fileobject)</dt><dd><tt>This&nbsp;method&nbsp;is&nbsp;no&nbsp;longer&nbsp;supported&nbsp;or&nbsp;allowed.</tt></dd></dl>
730
731 <dl><dt><a name="spawn-setmaxread"><strong>setmaxread</strong></a>(self, maxread)</dt><dd><tt>This&nbsp;method&nbsp;is&nbsp;no&nbsp;longer&nbsp;supported&nbsp;or&nbsp;allowed.&nbsp;I&nbsp;don't&nbsp;like&nbsp;getters<br>
732 and&nbsp;setters&nbsp;without&nbsp;a&nbsp;good&nbsp;reason.</tt></dd></dl>
733
734 <dl><dt><a name="spawn-setwinsize"><strong>setwinsize</strong></a>(self, r, c)</dt><dd><tt>This&nbsp;sets&nbsp;the&nbsp;terminal&nbsp;window&nbsp;size&nbsp;of&nbsp;the&nbsp;child&nbsp;tty.&nbsp;This&nbsp;will&nbsp;cause<br>
735 a&nbsp;SIGWINCH&nbsp;signal&nbsp;to&nbsp;be&nbsp;sent&nbsp;to&nbsp;the&nbsp;child.&nbsp;This&nbsp;does&nbsp;not&nbsp;change&nbsp;the<br>
736 physical&nbsp;window&nbsp;size.&nbsp;It&nbsp;changes&nbsp;the&nbsp;size&nbsp;reported&nbsp;to&nbsp;TTY-aware<br>
737 applications&nbsp;like&nbsp;vi&nbsp;or&nbsp;curses&nbsp;--&nbsp;applications&nbsp;that&nbsp;respond&nbsp;to&nbsp;the<br>
738 SIGWINCH&nbsp;signal.</tt></dd></dl>
739
740 <dl><dt><a name="spawn-terminate"><strong>terminate</strong></a>(self, force<font color="#909090">=False</font>)</dt><dd><tt>This&nbsp;forces&nbsp;a&nbsp;child&nbsp;process&nbsp;to&nbsp;terminate.&nbsp;It&nbsp;starts&nbsp;nicely&nbsp;with<br>
741 SIGHUP&nbsp;and&nbsp;SIGINT.&nbsp;If&nbsp;"force"&nbsp;is&nbsp;True&nbsp;then&nbsp;moves&nbsp;onto&nbsp;SIGKILL.&nbsp;This<br>
742 returns&nbsp;True&nbsp;if&nbsp;the&nbsp;child&nbsp;was&nbsp;terminated.&nbsp;This&nbsp;returns&nbsp;False&nbsp;if&nbsp;the<br>
743 child&nbsp;could&nbsp;not&nbsp;be&nbsp;terminated.</tt></dd></dl>
744
745 <dl><dt><a name="spawn-wait"><strong>wait</strong></a>(self)</dt><dd><tt>This&nbsp;waits&nbsp;until&nbsp;the&nbsp;child&nbsp;exits.&nbsp;This&nbsp;is&nbsp;a&nbsp;blocking&nbsp;call.&nbsp;This&nbsp;will<br>
746 not&nbsp;read&nbsp;any&nbsp;data&nbsp;from&nbsp;the&nbsp;child,&nbsp;so&nbsp;this&nbsp;will&nbsp;block&nbsp;forever&nbsp;if&nbsp;the<br>
747 child&nbsp;has&nbsp;unread&nbsp;output&nbsp;and&nbsp;has&nbsp;terminated.&nbsp;In&nbsp;other&nbsp;words,&nbsp;the&nbsp;child<br>
748 may&nbsp;have&nbsp;printed&nbsp;output&nbsp;then&nbsp;called&nbsp;exit();&nbsp;but,&nbsp;technically,&nbsp;the&nbsp;child<br>
749 is&nbsp;still&nbsp;alive&nbsp;until&nbsp;its&nbsp;output&nbsp;is&nbsp;read.</tt></dd></dl>
750
751 <dl><dt><a name="spawn-waitnoecho"><strong>waitnoecho</strong></a>(self, timeout<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;waits&nbsp;until&nbsp;the&nbsp;terminal&nbsp;ECHO&nbsp;flag&nbsp;is&nbsp;set&nbsp;False.&nbsp;This&nbsp;returns<br>
752 True&nbsp;if&nbsp;the&nbsp;echo&nbsp;mode&nbsp;is&nbsp;off.&nbsp;This&nbsp;returns&nbsp;False&nbsp;if&nbsp;the&nbsp;ECHO&nbsp;flag&nbsp;was<br>
753 not&nbsp;set&nbsp;False&nbsp;before&nbsp;the&nbsp;timeout.&nbsp;This&nbsp;can&nbsp;be&nbsp;used&nbsp;to&nbsp;detect&nbsp;when&nbsp;the<br>
754 child&nbsp;is&nbsp;waiting&nbsp;for&nbsp;a&nbsp;password.&nbsp;Usually&nbsp;a&nbsp;child&nbsp;application&nbsp;will&nbsp;turn<br>
755 off&nbsp;echo&nbsp;mode&nbsp;when&nbsp;it&nbsp;is&nbsp;waiting&nbsp;for&nbsp;the&nbsp;user&nbsp;to&nbsp;enter&nbsp;a&nbsp;password.&nbsp;For<br>
756 example,&nbsp;instead&nbsp;of&nbsp;expecting&nbsp;the&nbsp;"password:"&nbsp;prompt&nbsp;you&nbsp;can&nbsp;wait&nbsp;for<br>
757 the&nbsp;child&nbsp;to&nbsp;set&nbsp;ECHO&nbsp;off::<br>
758 &nbsp;<br>
759 &nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>&nbsp;('ssh&nbsp;[email protected]')<br>
760 &nbsp;&nbsp;&nbsp;&nbsp;p.<a href="#spawn-waitnoecho">waitnoecho</a>()<br>
761 &nbsp;&nbsp;&nbsp;&nbsp;p.<a href="#spawn-sendline">sendline</a>(mypassword)<br>
762 &nbsp;<br>
763 If&nbsp;timeout&nbsp;is&nbsp;None&nbsp;then&nbsp;this&nbsp;method&nbsp;to&nbsp;block&nbsp;forever&nbsp;until&nbsp;ECHO&nbsp;flag&nbsp;is<br>
764 False.</tt></dd></dl>
765
766 <dl><dt><a name="spawn-write"><strong>write</strong></a>(self, s)</dt><dd><tt>This&nbsp;is&nbsp;similar&nbsp;to&nbsp;<a href="#spawn-send">send</a>()&nbsp;except&nbsp;that&nbsp;there&nbsp;is&nbsp;no&nbsp;return&nbsp;value.</tt></dd></dl>
767
768 <dl><dt><a name="spawn-writelines"><strong>writelines</strong></a>(self, sequence)</dt><dd><tt>This&nbsp;calls&nbsp;<a href="#spawn-write">write</a>()&nbsp;for&nbsp;each&nbsp;element&nbsp;in&nbsp;the&nbsp;sequence.&nbsp;The&nbsp;sequence<br>
769 can&nbsp;be&nbsp;any&nbsp;iterable&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;producing&nbsp;strings,&nbsp;typically&nbsp;a&nbsp;list&nbsp;of<br>
770 strings.&nbsp;This&nbsp;does&nbsp;not&nbsp;add&nbsp;line&nbsp;separators&nbsp;There&nbsp;is&nbsp;no&nbsp;return&nbsp;value.</tt></dd></dl>
771
772 <hr>
773 Data descriptors defined here:<br>
774 <dl><dt><strong>__dict__</strong></dt>
775 <dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
776 </dl>
777 <dl><dt><strong>__weakref__</strong></dt>
778 <dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
779 </dl>
780 </td></tr></table></td></tr></table><p>
781 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
782 <tr bgcolor="#eeaa77">
783 <td colspan=3 valign=bottom>&nbsp;<br>
784 <font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
785     
786 <tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
787 <td width="100%"><dl><dt><a name="-run"><strong>run</strong></a>(command, timeout<font color="#909090">=-1</font>, withexitstatus<font color="#909090">=False</font>, events<font color="#909090">=None</font>, extra_args<font color="#909090">=None</font>, logfile<font color="#909090">=None</font>, cwd<font color="#909090">=None</font>, env<font color="#909090">=None</font>)</dt><dd><tt>This&nbsp;function&nbsp;runs&nbsp;the&nbsp;given&nbsp;command;&nbsp;waits&nbsp;for&nbsp;it&nbsp;to&nbsp;finish;&nbsp;then<br>
788 returns&nbsp;all&nbsp;output&nbsp;as&nbsp;a&nbsp;string.&nbsp;STDERR&nbsp;is&nbsp;included&nbsp;in&nbsp;output.&nbsp;If&nbsp;the&nbsp;full<br>
789 path&nbsp;to&nbsp;the&nbsp;command&nbsp;is&nbsp;not&nbsp;given&nbsp;then&nbsp;the&nbsp;path&nbsp;is&nbsp;searched.<br>
790 &nbsp;<br>
791 Note&nbsp;that&nbsp;lines&nbsp;are&nbsp;terminated&nbsp;by&nbsp;CR/LF&nbsp;(\r\n)&nbsp;combination&nbsp;even&nbsp;on<br>
792 UNIX-like&nbsp;systems&nbsp;because&nbsp;this&nbsp;is&nbsp;the&nbsp;standard&nbsp;for&nbsp;pseudo&nbsp;ttys.&nbsp;If&nbsp;you&nbsp;set<br>
793 'withexitstatus'&nbsp;to&nbsp;true,&nbsp;then&nbsp;run&nbsp;will&nbsp;return&nbsp;a&nbsp;tuple&nbsp;of&nbsp;(command_output,<br>
794 exitstatus).&nbsp;If&nbsp;'withexitstatus'&nbsp;is&nbsp;false&nbsp;then&nbsp;this&nbsp;returns&nbsp;just<br>
795 command_output.<br>
796 &nbsp;<br>
797 The&nbsp;<a href="#-run">run</a>()&nbsp;function&nbsp;can&nbsp;often&nbsp;be&nbsp;used&nbsp;instead&nbsp;of&nbsp;creating&nbsp;a&nbsp;<a href="#spawn">spawn</a>&nbsp;instance.<br>
798 For&nbsp;example,&nbsp;the&nbsp;following&nbsp;code&nbsp;uses&nbsp;<a href="#spawn">spawn</a>::<br>
799 &nbsp;<br>
800 &nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;pexpect&nbsp;import&nbsp;*<br>
801 &nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;<a href="#spawn">spawn</a>('scp&nbsp;foo&nbsp;[email protected]:.')<br>
802 &nbsp;&nbsp;&nbsp;&nbsp;child.expect&nbsp;('(?i)password')<br>
803 &nbsp;&nbsp;&nbsp;&nbsp;child.sendline&nbsp;(mypassword)<br>
804 &nbsp;<br>
805 The&nbsp;previous&nbsp;code&nbsp;can&nbsp;be&nbsp;replace&nbsp;with&nbsp;the&nbsp;following::<br>
806 &nbsp;<br>
807 &nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;pexpect&nbsp;import&nbsp;*<br>
808 &nbsp;&nbsp;&nbsp;&nbsp;run&nbsp;('scp&nbsp;foo&nbsp;[email protected]:.',&nbsp;events={'(?i)password':&nbsp;mypassword})<br>
809 &nbsp;<br>
810 Examples<br>
811 ========<br>
812 &nbsp;<br>
813 Start&nbsp;the&nbsp;apache&nbsp;daemon&nbsp;on&nbsp;the&nbsp;local&nbsp;machine::<br>
814 &nbsp;<br>
815 &nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;pexpect&nbsp;import&nbsp;*<br>
816 &nbsp;&nbsp;&nbsp;&nbsp;run&nbsp;("/usr/local/apache/bin/apachectl&nbsp;start")<br>
817 &nbsp;<br>
818 Check&nbsp;in&nbsp;a&nbsp;file&nbsp;using&nbsp;SVN::<br>
819 &nbsp;<br>
820 &nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;pexpect&nbsp;import&nbsp;*<br>
821 &nbsp;&nbsp;&nbsp;&nbsp;run&nbsp;("svn&nbsp;ci&nbsp;-m&nbsp;'automatic&nbsp;commit'&nbsp;my_file.py")<br>
822 &nbsp;<br>
823 Run&nbsp;a&nbsp;command&nbsp;and&nbsp;capture&nbsp;exit&nbsp;status::<br>
824 &nbsp;<br>
825 &nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;pexpect&nbsp;import&nbsp;*<br>
826 &nbsp;&nbsp;&nbsp;&nbsp;(command_output,&nbsp;exitstatus)&nbsp;=&nbsp;run&nbsp;('ls&nbsp;-l&nbsp;/bin',&nbsp;withexitstatus=1)<br>
827 &nbsp;<br>
828 Tricky&nbsp;Examples<br>
829 ===============<br>
830 &nbsp;<br>
831 The&nbsp;following&nbsp;will&nbsp;run&nbsp;SSH&nbsp;and&nbsp;execute&nbsp;'ls&nbsp;-l'&nbsp;on&nbsp;the&nbsp;remote&nbsp;machine.&nbsp;The<br>
832 password&nbsp;'secret'&nbsp;will&nbsp;be&nbsp;sent&nbsp;if&nbsp;the&nbsp;'(?i)password'&nbsp;pattern&nbsp;is&nbsp;ever&nbsp;seen::<br>
833 &nbsp;<br>
834 &nbsp;&nbsp;&nbsp;&nbsp;run&nbsp;("ssh&nbsp;[email protected]&nbsp;'ls&nbsp;-l'",&nbsp;events={'(?i)password':'secret\n'})<br>
835 &nbsp;<br>
836 This&nbsp;will&nbsp;start&nbsp;mencoder&nbsp;to&nbsp;rip&nbsp;a&nbsp;video&nbsp;from&nbsp;DVD.&nbsp;This&nbsp;will&nbsp;also&nbsp;display<br>
837 progress&nbsp;ticks&nbsp;every&nbsp;5&nbsp;seconds&nbsp;as&nbsp;it&nbsp;runs.&nbsp;For&nbsp;example::<br>
838 &nbsp;<br>
839 &nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;pexpect&nbsp;import&nbsp;*<br>
840 &nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;print_ticks(d):<br>
841 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;d['event_count'],<br>
842 &nbsp;&nbsp;&nbsp;&nbsp;run&nbsp;("mencoder&nbsp;dvd://1&nbsp;-o&nbsp;video.avi&nbsp;-oac&nbsp;copy&nbsp;-ovc&nbsp;copy",&nbsp;events={<a href="#TIMEOUT">TIMEOUT</a>:print_ticks},&nbsp;timeout=5)<br>
843 &nbsp;<br>
844 The&nbsp;'events'&nbsp;argument&nbsp;should&nbsp;be&nbsp;a&nbsp;dictionary&nbsp;of&nbsp;patterns&nbsp;and&nbsp;responses.<br>
845 Whenever&nbsp;one&nbsp;of&nbsp;the&nbsp;patterns&nbsp;is&nbsp;seen&nbsp;in&nbsp;the&nbsp;command&nbsp;out&nbsp;<a href="#-run">run</a>()&nbsp;will&nbsp;send&nbsp;the<br>
846 associated&nbsp;response&nbsp;string.&nbsp;Note&nbsp;that&nbsp;you&nbsp;should&nbsp;put&nbsp;newlines&nbsp;in&nbsp;your<br>
847 string&nbsp;if&nbsp;Enter&nbsp;is&nbsp;necessary.&nbsp;The&nbsp;responses&nbsp;may&nbsp;also&nbsp;contain&nbsp;callback<br>
848 functions.&nbsp;Any&nbsp;callback&nbsp;is&nbsp;function&nbsp;that&nbsp;takes&nbsp;a&nbsp;dictionary&nbsp;as&nbsp;an&nbsp;argument.<br>
849 The&nbsp;dictionary&nbsp;contains&nbsp;all&nbsp;the&nbsp;locals&nbsp;from&nbsp;the&nbsp;<a href="#-run">run</a>()&nbsp;function,&nbsp;so&nbsp;you&nbsp;can<br>
850 access&nbsp;the&nbsp;child&nbsp;<a href="#spawn">spawn</a>&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;or&nbsp;any&nbsp;other&nbsp;variable&nbsp;defined&nbsp;in&nbsp;<a href="#-run">run</a>()<br>
851 (event_count,&nbsp;child,&nbsp;and&nbsp;extra_args&nbsp;are&nbsp;the&nbsp;most&nbsp;useful).&nbsp;A&nbsp;callback&nbsp;may<br>
852 return&nbsp;True&nbsp;to&nbsp;stop&nbsp;the&nbsp;current&nbsp;run&nbsp;process&nbsp;otherwise&nbsp;<a href="#-run">run</a>()&nbsp;continues&nbsp;until<br>
853 the&nbsp;next&nbsp;event.&nbsp;A&nbsp;callback&nbsp;may&nbsp;also&nbsp;return&nbsp;a&nbsp;string&nbsp;which&nbsp;will&nbsp;be&nbsp;sent&nbsp;to<br>
854 the&nbsp;child.&nbsp;'extra_args'&nbsp;is&nbsp;not&nbsp;used&nbsp;by&nbsp;directly&nbsp;<a href="#-run">run</a>().&nbsp;It&nbsp;provides&nbsp;a&nbsp;way&nbsp;to<br>
855 pass&nbsp;data&nbsp;to&nbsp;a&nbsp;callback&nbsp;function&nbsp;through&nbsp;<a href="#-run">run</a>()&nbsp;through&nbsp;the&nbsp;locals<br>
856 dictionary&nbsp;passed&nbsp;to&nbsp;a&nbsp;callback.</tt></dd></dl>
857  <dl><dt><a name="-split_command_line"><strong>split_command_line</strong></a>(command_line)</dt><dd><tt>This&nbsp;splits&nbsp;a&nbsp;command&nbsp;line&nbsp;into&nbsp;a&nbsp;list&nbsp;of&nbsp;arguments.&nbsp;It&nbsp;splits&nbsp;arguments<br>
858 on&nbsp;spaces,&nbsp;but&nbsp;handles&nbsp;embedded&nbsp;quotes,&nbsp;doublequotes,&nbsp;and&nbsp;escaped<br>
859 characters.&nbsp;It's&nbsp;impossible&nbsp;to&nbsp;do&nbsp;this&nbsp;with&nbsp;a&nbsp;regular&nbsp;expression,&nbsp;so&nbsp;I<br>
860 wrote&nbsp;a&nbsp;little&nbsp;state&nbsp;machine&nbsp;to&nbsp;parse&nbsp;the&nbsp;command&nbsp;line.</tt></dd></dl>
861  <dl><dt><a name="-which"><strong>which</strong></a>(filename)</dt><dd><tt>This&nbsp;takes&nbsp;a&nbsp;given&nbsp;filename;&nbsp;tries&nbsp;to&nbsp;find&nbsp;it&nbsp;in&nbsp;the&nbsp;environment&nbsp;path;<br>
862 then&nbsp;checks&nbsp;if&nbsp;it&nbsp;is&nbsp;executable.&nbsp;This&nbsp;returns&nbsp;the&nbsp;full&nbsp;path&nbsp;to&nbsp;the&nbsp;filename<br>
863 if&nbsp;found&nbsp;and&nbsp;executable.&nbsp;Otherwise&nbsp;this&nbsp;returns&nbsp;None.</tt></dd></dl>
864 </td></tr></table><p>
865 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
866 <tr bgcolor="#55aa55">
867 <td colspan=3 valign=bottom>&nbsp;<br>
868 <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
869     
870 <tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
871 <td width="100%"><strong>__all__</strong> = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn', 'run', 'which', 'split_command_line', '__version__', '__revision__']<br>
872 <strong>__revision__</strong> = '$Revision: 399 $'<br>
873 <strong>__version__</strong> = '2.3'</td></tr></table>
874 </body></html>

UCC git Repository :: git.ucc.asn.au