File: pexpect.html

package info (click to toggle)
pexpect 2.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 584 kB
  • ctags: 701
  • sloc: python: 3,036; makefile: 46
file content (653 lines) | stat: -rw-r--r-- 61,497 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653

<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module pexpect</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>pexpect</strong></big></big> (version 2.1)</font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/noah/documents/export/engineering/source/python/pexpect/trunk/pexpect/pexpect.py">/home/noah/documents/export/engineering/source/python/pexpect/trunk/pexpect/pexpect.py</a></font></td></tr></table>
    <p><tt>Pexpect&nbsp;is&nbsp;a&nbsp;Python&nbsp;module&nbsp;for&nbsp;spawning&nbsp;child&nbsp;applications&nbsp;and&nbsp;controlling<br>
them&nbsp;automatically.&nbsp;Pexpect&nbsp;can&nbsp;be&nbsp;used&nbsp;for&nbsp;automating&nbsp;interactive&nbsp;applications<br>
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>
scripts&nbsp;for&nbsp;duplicating&nbsp;software&nbsp;package&nbsp;installations&nbsp;on&nbsp;different&nbsp;servers.&nbsp;It<br>
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>
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>
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>
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>
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>
that&nbsp;simple&nbsp;tasks&nbsp;are&nbsp;easy.<br>
&nbsp;<br>
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>
<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>
output.&nbsp;This&nbsp;is&nbsp;a&nbsp;handy&nbsp;replacement&nbsp;for&nbsp;os.system().<br>
&nbsp;<br>
For&nbsp;example:<br>
&nbsp;&nbsp;&nbsp;&nbsp;pexpect.<a href="#-run">run</a>('ls&nbsp;-la')<br>
&nbsp;<br>
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>
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>
expecting&nbsp;responses.<br>
&nbsp;<br>
For&nbsp;example:<br>
&nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>('scp&nbsp;foo&nbsp;myname@host.example.com:.')<br>
&nbsp;&nbsp;&nbsp;&nbsp;child.expect&nbsp;('Password:')<br>
&nbsp;&nbsp;&nbsp;&nbsp;child.sendline&nbsp;(mypassword)<br>
&nbsp;<br>
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>
the&nbsp;normal&nbsp;stdio&nbsp;streams.<br>
&nbsp;<br>
Credits:<br>
Noah&nbsp;Spurrier,&nbsp;Richard&nbsp;Holden,&nbsp;Marco&nbsp;Molteni,&nbsp;Kimberley&nbsp;Burchett,&nbsp;Robert&nbsp;Stone,<br>
Hartmut&nbsp;Goebel,&nbsp;Chad&nbsp;Schroeder,&nbsp;Erick&nbsp;Tryzelaar,&nbsp;Dave&nbsp;Kirby,&nbsp;Ids&nbsp;vander&nbsp;Molen,<br>
George&nbsp;Todd,&nbsp;Noel&nbsp;Taylor,&nbsp;Nicolas&nbsp;D.&nbsp;Cesar,&nbsp;Alexander&nbsp;Gattin,<br>
Geoffrey&nbsp;Marshall,&nbsp;Francisco&nbsp;Lourenco,&nbsp;Glen&nbsp;Mabey,&nbsp;Karthik&nbsp;Gurusamy,<br>
Fernando&nbsp;Perez&nbsp;<br>
(Let&nbsp;me&nbsp;know&nbsp;if&nbsp;I&nbsp;forgot&nbsp;anyone.)<br>
&nbsp;<br>
Free,&nbsp;open&nbsp;source,&nbsp;and&nbsp;all&nbsp;that&nbsp;good&nbsp;stuff.<br>
&nbsp;<br>
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>
this&nbsp;software&nbsp;and&nbsp;associated&nbsp;documentation&nbsp;files&nbsp;(the&nbsp;"Software"),&nbsp;to&nbsp;deal&nbsp;in<br>
the&nbsp;Software&nbsp;without&nbsp;restriction,&nbsp;including&nbsp;without&nbsp;limitation&nbsp;the&nbsp;rights&nbsp;to<br>
use,&nbsp;copy,&nbsp;modify,&nbsp;merge,&nbsp;publish,&nbsp;distribute,&nbsp;sublicense,&nbsp;and/or&nbsp;sell&nbsp;copies<br>
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>
so,&nbsp;subject&nbsp;to&nbsp;the&nbsp;following&nbsp;conditions:<br>
&nbsp;<br>
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>
copies&nbsp;or&nbsp;substantial&nbsp;portions&nbsp;of&nbsp;the&nbsp;Software.<br>
&nbsp;<br>
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>
IMPLIED,&nbsp;INCLUDING&nbsp;BUT&nbsp;NOT&nbsp;LIMITED&nbsp;TO&nbsp;THE&nbsp;WARRANTIES&nbsp;OF&nbsp;MERCHANTABILITY,<br>
FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR&nbsp;PURPOSE&nbsp;AND&nbsp;NONINFRINGEMENT.&nbsp;IN&nbsp;NO&nbsp;EVENT&nbsp;SHALL&nbsp;THE<br>
AUTHORS&nbsp;OR&nbsp;COPYRIGHT&nbsp;HOLDERS&nbsp;BE&nbsp;LIABLE&nbsp;FOR&nbsp;ANY&nbsp;CLAIM,&nbsp;DAMAGES&nbsp;OR&nbsp;OTHER<br>
LIABILITY,&nbsp;WHETHER&nbsp;IN&nbsp;AN&nbsp;ACTION&nbsp;OF&nbsp;CONTRACT,&nbsp;TORT&nbsp;OR&nbsp;OTHERWISE,&nbsp;ARISING&nbsp;FROM,<br>
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>
SOFTWARE.<br>
&nbsp;<br>
Pexpect&nbsp;Copyright&nbsp;(c)&nbsp;2006&nbsp;Noah&nbsp;Spurrier<br>
<a href="http://pexpect.sourceforge.net/">http://pexpect.sourceforge.net/</a><br>
&nbsp;<br>
$Revision:&nbsp;395&nbsp;$<br>
$Date:&nbsp;2006-05-31&nbsp;20:07:18&nbsp;-0700&nbsp;(Wed,&nbsp;31&nbsp;May&nbsp;2006)&nbsp;$</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="errno.html">errno</a><br>
<a href="fcntl.html">fcntl</a><br>
<a href="os.html">os</a><br>
<a href="pty.html">pty</a><br>
</td><td width="25%" valign=top><a href="re.html">re</a><br>
<a href="resource.html">resource</a><br>
<a href="select.html">select</a><br>
<a href="signal.html">signal</a><br>
</td><td width="25%" valign=top><a href="string.html">string</a><br>
<a href="struct.html">struct</a><br>
<a href="sys.html">sys</a><br>
<a href="termios.html">termios</a><br>
</td><td width="25%" valign=top><a href="time.html">time</a><br>
<a href="traceback.html">traceback</a><br>
<a href="tty.html">tty</a><br>
<a href="types.html">types</a><br>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
    
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="pexpect.html#spawn">spawn</a>
</font></dt></dl>
</dd>
<dt><font face="helvetica, arial"><a href="exceptions.html#Exception">exceptions.Exception</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="pexpect.html#EOF">EOF</a>
</font></dt><dt><font face="helvetica, arial"><a href="pexpect.html#TIMEOUT">TIMEOUT</a>
</font></dt></dl>
</dd>
</dl>
</dd>
</dl>
 <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="EOF">class <strong>EOF</strong></a>(<a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>Raised&nbsp;when&nbsp;<a href="#EOF">EOF</a>&nbsp;is&nbsp;read&nbsp;from&nbsp;a&nbsp;child.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="pexpect.html#EOF">EOF</a></dd>
<dd><a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a></dd>
<dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd>
</dl>
<hr>
Methods inherited from <a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a>:<br>
<dl><dt><a name="EOF-__init__"><strong>__init__</strong></a>(self, value)</dt></dl>

<dl><dt><a name="EOF-__str__"><strong>__str__</strong></a>(self)</dt></dl>

<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&nbsp;the&nbsp;caller.<br>
In&nbsp;other&nbsp;words,&nbsp;the&nbsp;stack&nbsp;trace&nbsp;inside&nbsp;the&nbsp;Pexpect&nbsp;module&nbsp;is&nbsp;not&nbsp;included.</tt></dd></dl>

<hr>
Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
<dl><dt><a name="EOF-__getitem__"><strong>__getitem__</strong></a>(...)</dt></dl>

</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<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>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<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>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="ExceptionPexpect-__init__"><strong>__init__</strong></a>(self, value)</dt></dl>

<dl><dt><a name="ExceptionPexpect-__str__"><strong>__str__</strong></a>(self)</dt></dl>

<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&nbsp;the&nbsp;caller.<br>
In&nbsp;other&nbsp;words,&nbsp;the&nbsp;stack&nbsp;trace&nbsp;inside&nbsp;the&nbsp;Pexpect&nbsp;module&nbsp;is&nbsp;not&nbsp;included.</tt></dd></dl>

<hr>
Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
<dl><dt><a name="ExceptionPexpect-__getitem__"><strong>__getitem__</strong></a>(...)</dt></dl>

</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="TIMEOUT">class <strong>TIMEOUT</strong></a>(<a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>Raised&nbsp;when&nbsp;a&nbsp;read&nbsp;time&nbsp;exceeds&nbsp;the&nbsp;timeout.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="pexpect.html#TIMEOUT">TIMEOUT</a></dd>
<dd><a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a></dd>
<dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd>
</dl>
<hr>
Methods inherited from <a href="pexpect.html#ExceptionPexpect">ExceptionPexpect</a>:<br>
<dl><dt><a name="TIMEOUT-__init__"><strong>__init__</strong></a>(self, value)</dt></dl>

<dl><dt><a name="TIMEOUT-__str__"><strong>__str__</strong></a>(self)</dt></dl>

<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&nbsp;the&nbsp;caller.<br>
In&nbsp;other&nbsp;words,&nbsp;the&nbsp;stack&nbsp;trace&nbsp;inside&nbsp;the&nbsp;Pexpect&nbsp;module&nbsp;is&nbsp;not&nbsp;included.</tt></dd></dl>

<hr>
Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
<dl><dt><a name="TIMEOUT-__getitem__"><strong>__getitem__</strong></a>(...)</dt></dl>

</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<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>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>This&nbsp;is&nbsp;the&nbsp;main&nbsp;class&nbsp;interface&nbsp;for&nbsp;Pexpect.<br>
Use&nbsp;this&nbsp;class&nbsp;to&nbsp;start&nbsp;and&nbsp;control&nbsp;child&nbsp;applications.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<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.<br>
Python&nbsp;only&nbsp;garbage&nbsp;collects&nbsp;Python&nbsp;objects.&nbsp;OS&nbsp;file&nbsp;descriptors<br>
are&nbsp;not&nbsp;Python&nbsp;objects,&nbsp;so&nbsp;they&nbsp;must&nbsp;be&nbsp;handled&nbsp;explicitly.<br>
If&nbsp;the&nbsp;child&nbsp;file&nbsp;descriptor&nbsp;was&nbsp;opened&nbsp;outside&nbsp;of&nbsp;this&nbsp;class<br>
(passed&nbsp;to&nbsp;the&nbsp;constructor)&nbsp;then&nbsp;this&nbsp;does&nbsp;not&nbsp;close&nbsp;it.</tt></dd></dl>

<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>, 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<br>
that&nbsp;includes&nbsp;a&nbsp;command&nbsp;and&nbsp;any&nbsp;arguments&nbsp;to&nbsp;the&nbsp;command.&nbsp;For&nbsp;example:<br>
&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>&nbsp;('/usr/bin/ftp')<br>
&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>&nbsp;('/usr/bin/ssh&nbsp;user@example.com')<br>
&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>&nbsp;('ls&nbsp;-latr&nbsp;/tmp')<br>
You&nbsp;may&nbsp;also&nbsp;construct&nbsp;it&nbsp;with&nbsp;a&nbsp;list&nbsp;of&nbsp;arguments&nbsp;like&nbsp;so:<br>
&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>&nbsp;('/usr/bin/ftp',&nbsp;[])<br>
&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>&nbsp;('/usr/bin/ssh',&nbsp;['user@example.com'])<br>
&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>&nbsp;('ls',&nbsp;['-latr',&nbsp;'/tmp'])<br>
After&nbsp;this&nbsp;the&nbsp;child&nbsp;application&nbsp;will&nbsp;be&nbsp;created&nbsp;and<br>
will&nbsp;be&nbsp;ready&nbsp;to&nbsp;talk&nbsp;to.&nbsp;For&nbsp;normal&nbsp;use,&nbsp;see&nbsp;<a href="#spawn-expect">expect</a>()&nbsp;and&nbsp;<br>
<a href="#spawn-send">send</a>()&nbsp;and&nbsp;<a href="#spawn-sendline">sendline</a>().<br>
&nbsp;<br>
The&nbsp;maxread&nbsp;attribute&nbsp;sets&nbsp;the&nbsp;read&nbsp;buffer&nbsp;size.<br>
This&nbsp;is&nbsp;maximum&nbsp;number&nbsp;of&nbsp;bytes&nbsp;that&nbsp;Pexpect&nbsp;will&nbsp;try&nbsp;to&nbsp;read<br>
from&nbsp;a&nbsp;TTY&nbsp;at&nbsp;one&nbsp;time.<br>
Seeting&nbsp;the&nbsp;maxread&nbsp;size&nbsp;to&nbsp;1&nbsp;will&nbsp;turn&nbsp;off&nbsp;buffering.<br>
Setting&nbsp;the&nbsp;maxread&nbsp;value&nbsp;higher&nbsp;may&nbsp;help&nbsp;performance&nbsp;in&nbsp;cases<br>
where&nbsp;large&nbsp;amounts&nbsp;of&nbsp;output&nbsp;are&nbsp;read&nbsp;back&nbsp;from&nbsp;the&nbsp;child.<br>
This&nbsp;feature&nbsp;is&nbsp;useful&nbsp;in&nbsp;conjunction&nbsp;with&nbsp;searchwindowsize.<br>
&nbsp;<br>
The&nbsp;searchwindowsize&nbsp;attribute&nbsp;sets&nbsp;the&nbsp;how&nbsp;far&nbsp;back&nbsp;in<br>
the&nbsp;incomming&nbsp;seach&nbsp;buffer&nbsp;Pexpect&nbsp;will&nbsp;search&nbsp;for&nbsp;pattern&nbsp;matches.<br>
Every&nbsp;time&nbsp;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<br>
the&nbsp;incomming&nbsp;buffer.&nbsp;The&nbsp;default&nbsp;is&nbsp;to&nbsp;search&nbsp;from&nbsp;the&nbsp;beginning&nbsp;of&nbsp;the<br>
imcomming&nbsp;buffer&nbsp;each&nbsp;time&nbsp;new&nbsp;data&nbsp;is&nbsp;read&nbsp;from&nbsp;the&nbsp;child.<br>
But&nbsp;this&nbsp;is&nbsp;very&nbsp;inefficient&nbsp;if&nbsp;you&nbsp;are&nbsp;running&nbsp;a&nbsp;command&nbsp;that<br>
generates&nbsp;a&nbsp;large&nbsp;amount&nbsp;of&nbsp;data&nbsp;where&nbsp;you&nbsp;want&nbsp;to&nbsp;match<br>
The&nbsp;searchwindowsize&nbsp;does&nbsp;not&nbsp;effect&nbsp;the&nbsp;size&nbsp;of&nbsp;the&nbsp;incomming&nbsp;data&nbsp;buffer.<br>
You&nbsp;will&nbsp;still&nbsp;have&nbsp;access&nbsp;to&nbsp;the&nbsp;full&nbsp;buffer&nbsp;after&nbsp;<a href="#spawn-expect">expect</a>()&nbsp;returns.<br>
&nbsp;<br>
The&nbsp;logfile&nbsp;member&nbsp;turns&nbsp;on&nbsp;or&nbsp;off&nbsp;logging.<br>
All&nbsp;input&nbsp;and&nbsp;output&nbsp;will&nbsp;be&nbsp;copied&nbsp;to&nbsp;the&nbsp;given&nbsp;file&nbsp;<a href="__builtin__.html#object">object</a>.<br>
Set&nbsp;logfile&nbsp;to&nbsp;None&nbsp;to&nbsp;stop&nbsp;logging.&nbsp;This&nbsp;is&nbsp;the&nbsp;default.<br>
Set&nbsp;logfile&nbsp;to&nbsp;sys.stdout&nbsp;to&nbsp;echo&nbsp;everything&nbsp;to&nbsp;standard&nbsp;output.<br>
The&nbsp;logfile&nbsp;is&nbsp;flushed&nbsp;after&nbsp;each&nbsp;write.<br>
Example&nbsp;1:<br>
&nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>('some_command')<br>
&nbsp;&nbsp;&nbsp;&nbsp;fout&nbsp;=&nbsp;file('mylog.txt','w')<br>
&nbsp;&nbsp;&nbsp;&nbsp;child.logfile&nbsp;=&nbsp;fout<br>
Example&nbsp;2:<br>
&nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>('some_command')<br>
&nbsp;&nbsp;&nbsp;&nbsp;child.logfile&nbsp;=&nbsp;sys.stdout<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
The&nbsp;delaybeforesend&nbsp;helps&nbsp;overcome&nbsp;a&nbsp;weird&nbsp;behavior&nbsp;that&nbsp;many&nbsp;users&nbsp;were&nbsp;experiencing.<br>
The&nbsp;typical&nbsp;problem&nbsp;was&nbsp;that&nbsp;a&nbsp;user&nbsp;would&nbsp;<a href="#spawn-expect">expect</a>()&nbsp;a&nbsp;"Password:"&nbsp;prompt&nbsp;and<br>
then&nbsp;immediately&nbsp;call&nbsp;<a href="#spawn-sendline">sendline</a>()&nbsp;to&nbsp;send&nbsp;the&nbsp;password.&nbsp;The&nbsp;user&nbsp;would&nbsp;then<br>
see&nbsp;that&nbsp;their&nbsp;password&nbsp;was&nbsp;echoed&nbsp;back&nbsp;to&nbsp;them.&nbsp;Passwords&nbsp;don't<br>
normally&nbsp;echo.&nbsp;The&nbsp;problem&nbsp;is&nbsp;caused&nbsp;by&nbsp;the&nbsp;fact&nbsp;that&nbsp;most&nbsp;applications<br>
print&nbsp;out&nbsp;the&nbsp;"Password"&nbsp;prompt&nbsp;and&nbsp;then&nbsp;turn&nbsp;off&nbsp;stdin&nbsp;echo,&nbsp;but&nbsp;if&nbsp;you<br>
send&nbsp;your&nbsp;password&nbsp;before&nbsp;the&nbsp;application&nbsp;turned&nbsp;off&nbsp;echo,&nbsp;then&nbsp;you&nbsp;get<br>
your&nbsp;password&nbsp;echoed.&nbsp;Normally&nbsp;this&nbsp;wouldn't&nbsp;be&nbsp;a&nbsp;problem&nbsp;when&nbsp;interacting<br>
with&nbsp;a&nbsp;human&nbsp;at&nbsp;a&nbsp;real&nbsp;heyboard.&nbsp;If&nbsp;you&nbsp;introduce&nbsp;a&nbsp;slight&nbsp;delay&nbsp;just&nbsp;before&nbsp;<br>
writing&nbsp;then&nbsp;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;<br>
for&nbsp;many&nbsp;users&nbsp;that&nbsp;I&nbsp;decided&nbsp;that&nbsp;the&nbsp;default&nbsp;pexpect&nbsp;behavior<br>
should&nbsp;be&nbsp;to&nbsp;sleep&nbsp;just&nbsp;before&nbsp;writing&nbsp;to&nbsp;the&nbsp;child&nbsp;application.<br>
1/10th&nbsp;of&nbsp;a&nbsp;second&nbsp;(100&nbsp;ms)&nbsp;seems&nbsp;to&nbsp;be&nbsp;enough&nbsp;to&nbsp;clear&nbsp;up&nbsp;the&nbsp;problem.<br>
You&nbsp;can&nbsp;set&nbsp;delaybeforesend&nbsp;to&nbsp;0&nbsp;to&nbsp;return&nbsp;to&nbsp;the&nbsp;old&nbsp;behavior.<br>
&nbsp;<br>
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>
It&nbsp;uses&nbsp;the&nbsp;same&nbsp;logic&nbsp;that&nbsp;"which"&nbsp;uses&nbsp;to&nbsp;find&nbsp;executables.<br>
&nbsp;<br>
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<br>
the&nbsp;<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<br>
stored&nbsp;in&nbsp;self.<strong>exitstatus</strong>&nbsp;or&nbsp;self.<strong>signalstatus</strong>.<br>
If&nbsp;the&nbsp;child&nbsp;exited&nbsp;normally&nbsp;then&nbsp;exitstatus&nbsp;will&nbsp;store&nbsp;the&nbsp;exit&nbsp;return&nbsp;code&nbsp;and<br>
signalstatus&nbsp;will&nbsp;be&nbsp;None.<br>
If&nbsp;the&nbsp;child&nbsp;was&nbsp;terminated&nbsp;abnormally&nbsp;with&nbsp;a&nbsp;signal&nbsp;then&nbsp;signalstatus&nbsp;will&nbsp;store<br>
the&nbsp;signal&nbsp;value&nbsp;and&nbsp;exitstatus&nbsp;will&nbsp;be&nbsp;None.<br>
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&nbsp;stores<br>
the&nbsp;status&nbsp;returned&nbsp;by&nbsp;os.waitpid.&nbsp;You&nbsp;can&nbsp;interpret&nbsp;this&nbsp;using<br>
os.WIFEXITED/os.WEXITSTATUS&nbsp;or&nbsp;os.WIFSIGNALED/os.TERMSIG.</tt></dd></dl>

<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>

<dl><dt><a name="spawn-__str__"><strong>__str__</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;the&nbsp;current&nbsp;state&nbsp;of&nbsp;the&nbsp;pexpect&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;as&nbsp;a&nbsp;string.</tt></dd></dl>

<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.<br>
Note&nbsp;that&nbsp;calling&nbsp;<a href="#spawn-close">close</a>()&nbsp;more&nbsp;than&nbsp;once&nbsp;is&nbsp;valid.<br>
This&nbsp;emulates&nbsp;standard&nbsp;Python&nbsp;behavior&nbsp;with&nbsp;files.<br>
Set&nbsp;force&nbsp;to&nbsp;True&nbsp;if&nbsp;you&nbsp;want&nbsp;to&nbsp;make&nbsp;sure&nbsp;that&nbsp;the&nbsp;child&nbsp;is&nbsp;terminated<br>
(SIGKILL&nbsp;is&nbsp;sent&nbsp;if&nbsp;the&nbsp;child&nbsp;ignores&nbsp;SIGHUP&nbsp;and&nbsp;SIGINT).</tt></dd></dl>

<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>
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;<br>
a&nbsp;list&nbsp;of&nbsp;those.&nbsp;Patterns&nbsp;may&nbsp;also&nbsp;be&nbsp;None&nbsp;which&nbsp;results&nbsp;in<br>
an&nbsp;empty&nbsp;list.<br>
&nbsp;<br>
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>().<br>
Thus&nbsp;<a href="#spawn-expect">expect</a>()&nbsp;is&nbsp;nothing&nbsp;more&nbsp;than::<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cpl&nbsp;=&nbsp;<a href="#spawn-compile_pattern_list">compile_pattern_list</a>(pl)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<a href="#spawn-expect_list">expect_list</a>(clp,&nbsp;timeout)<br>
&nbsp;<br>
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>
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>
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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cpl&nbsp;=&nbsp;<a href="#spawn-compile_pattern_list">compile_pattern_list</a>(my_pattern)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;some_condition:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i&nbsp;=&nbsp;<a href="#spawn-expect_list">expect_list</a>(clp,&nbsp;timeout)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...</tt></dd></dl>

<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>

<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.<br>
The&nbsp;pattern&nbsp;is&nbsp;overloaded&nbsp;and&nbsp;may&nbsp;take&nbsp;several&nbsp;types&nbsp;including&nbsp;a&nbsp;list.<br>
The&nbsp;pattern&nbsp;can&nbsp;be&nbsp;a&nbsp;StringType,&nbsp;<a href="#EOF">EOF</a>,&nbsp;a&nbsp;compiled&nbsp;re,&nbsp;or&nbsp;a&nbsp;list&nbsp;of<br>
those&nbsp;types.&nbsp;Strings&nbsp;will&nbsp;be&nbsp;compiled&nbsp;to&nbsp;re&nbsp;types.&nbsp;This&nbsp;returns&nbsp;the<br>
index&nbsp;into&nbsp;the&nbsp;pattern&nbsp;list.&nbsp;If&nbsp;the&nbsp;pattern&nbsp;was&nbsp;not&nbsp;a&nbsp;list&nbsp;this<br>
returns&nbsp;index&nbsp;0&nbsp;on&nbsp;a&nbsp;successful&nbsp;match.&nbsp;This&nbsp;may&nbsp;raise&nbsp;exceptions&nbsp;for<br>
<a href="#EOF">EOF</a>&nbsp;or&nbsp;<a href="#TIMEOUT">TIMEOUT</a>.&nbsp;To&nbsp;avoid&nbsp;the&nbsp;<a href="#EOF">EOF</a>&nbsp;or&nbsp;<a href="#TIMEOUT">TIMEOUT</a>&nbsp;exceptions&nbsp;add<br>
<a href="#EOF">EOF</a>&nbsp;or&nbsp;<a href="#TIMEOUT">TIMEOUT</a>&nbsp;to&nbsp;the&nbsp;pattern&nbsp;list.<br>
&nbsp;<br>
After&nbsp;a&nbsp;match&nbsp;is&nbsp;found&nbsp;the&nbsp;instance&nbsp;attributes<br>
'before',&nbsp;'after'&nbsp;and&nbsp;'match'&nbsp;will&nbsp;be&nbsp;set.<br>
You&nbsp;can&nbsp;see&nbsp;all&nbsp;the&nbsp;data&nbsp;read&nbsp;before&nbsp;the&nbsp;match&nbsp;in&nbsp;'before'.<br>
You&nbsp;can&nbsp;see&nbsp;the&nbsp;data&nbsp;that&nbsp;was&nbsp;matched&nbsp;in&nbsp;'after'.<br>
The&nbsp;re.MatchObject&nbsp;used&nbsp;in&nbsp;the&nbsp;re&nbsp;match&nbsp;will&nbsp;be&nbsp;in&nbsp;'match'.<br>
If&nbsp;an&nbsp;error&nbsp;occured&nbsp;then&nbsp;'before'&nbsp;will&nbsp;be&nbsp;set&nbsp;to&nbsp;all&nbsp;the<br>
data&nbsp;read&nbsp;so&nbsp;far&nbsp;and&nbsp;'after'&nbsp;and&nbsp;'match'&nbsp;will&nbsp;be&nbsp;None.<br>
&nbsp;<br>
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>
&nbsp;<br>
Note:&nbsp;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.<br>
This&nbsp;will&nbsp;catch&nbsp;these&nbsp;exceptions&nbsp;and&nbsp;return&nbsp;the&nbsp;index<br>
of&nbsp;the&nbsp;list&nbsp;entry&nbsp;instead&nbsp;of&nbsp;raising&nbsp;the&nbsp;exception.<br>
The&nbsp;attribute&nbsp;'after'&nbsp;will&nbsp;be&nbsp;set&nbsp;to&nbsp;the&nbsp;exception&nbsp;type.<br>
The&nbsp;attribute&nbsp;'match'&nbsp;will&nbsp;be&nbsp;None.<br>
This&nbsp;allows&nbsp;you&nbsp;to&nbsp;write&nbsp;code&nbsp;like&nbsp;this:<br>
&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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;index&nbsp;==&nbsp;0:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_something()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif&nbsp;index&nbsp;==&nbsp;1:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_something_else()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif&nbsp;index&nbsp;==&nbsp;2:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_some_other_thing()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif&nbsp;index&nbsp;==&nbsp;3:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_something_completely_different()<br>
instead&nbsp;of&nbsp;code&nbsp;like&nbsp;this:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index&nbsp;=&nbsp;p.expect&nbsp;(['good',&nbsp;'bad'])<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;index&nbsp;==&nbsp;0:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_something()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif&nbsp;index&nbsp;==&nbsp;1:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_something_else()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;except&nbsp;<a href="#EOF">EOF</a>:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_some_other_thing()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;except&nbsp;<a href="#TIMEOUT">TIMEOUT</a>:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_something_completely_different()<br>
These&nbsp;two&nbsp;forms&nbsp;are&nbsp;equivalent.&nbsp;It&nbsp;all&nbsp;depends&nbsp;on&nbsp;what&nbsp;you&nbsp;want.<br>
You&nbsp;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<br>
of&nbsp;a&nbsp;child&nbsp;to&nbsp;finish.&nbsp;For&nbsp;example:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>('/bin/ls')<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(pexpect.<a href="#EOF">EOF</a>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;p.before<br>
&nbsp;<br>
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>

<dl><dt><a name="spawn-expect_exact"><strong>expect_exact</strong></a>(self, pattern_list, timeout<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;method&nbsp;is&nbsp;no&nbsp;longer&nbsp;supported&nbsp;or&nbsp;allowed.<br>
It&nbsp;was&nbsp;too&nbsp;hard&nbsp;to&nbsp;maintain&nbsp;and&nbsp;keep&nbsp;it&nbsp;up&nbsp;to&nbsp;date&nbsp;with&nbsp;expect_list.<br>
Few&nbsp;people&nbsp;used&nbsp;this&nbsp;method.&nbsp;Most&nbsp;people&nbsp;favored&nbsp;reliability&nbsp;over&nbsp;speed.<br>
The&nbsp;implementation&nbsp;is&nbsp;left&nbsp;in&nbsp;comments&nbsp;in&nbsp;case&nbsp;anyone&nbsp;needs&nbsp;to&nbsp;hack&nbsp;this<br>
feature&nbsp;back&nbsp;into&nbsp;their&nbsp;copy.<br>
If&nbsp;someone&nbsp;wants&nbsp;to&nbsp;diff&nbsp;this&nbsp;with&nbsp;expect_list&nbsp;and&nbsp;make&nbsp;them&nbsp;work<br>
nearly&nbsp;the&nbsp;same&nbsp;then&nbsp;I&nbsp;will&nbsp;consider&nbsp;adding&nbsp;this&nbsp;make&nbsp;in.</tt></dd></dl>

<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;<br>
the&nbsp;index&nbsp;into&nbsp;the&nbsp;pattern_list&nbsp;that&nbsp;matched&nbsp;the&nbsp;child&nbsp;output.<br>
The&nbsp;list&nbsp;may&nbsp;also&nbsp;contain&nbsp;<a href="#EOF">EOF</a>&nbsp;or&nbsp;<a href="#TIMEOUT">TIMEOUT</a>&nbsp;(which&nbsp;are&nbsp;not<br>
compiled&nbsp;regular&nbsp;expressions).&nbsp;This&nbsp;method&nbsp;is&nbsp;similar&nbsp;to<br>
the&nbsp;<a href="#spawn-expect">expect</a>()&nbsp;method&nbsp;except&nbsp;that&nbsp;<a href="#spawn-expect_list">expect_list</a>()&nbsp;does&nbsp;not<br>
recompile&nbsp;the&nbsp;pattern&nbsp;list&nbsp;on&nbsp;every&nbsp;call.<br>
This&nbsp;may&nbsp;help&nbsp;if&nbsp;you&nbsp;are&nbsp;trying&nbsp;to&nbsp;optimize&nbsp;for&nbsp;speed,&nbsp;otherwise<br>
just&nbsp;use&nbsp;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>().<br>
If&nbsp;timeout==-1&nbsp;then&nbsp;the&nbsp;self.<strong>timeout</strong>&nbsp;value&nbsp;is&nbsp;used.<br>
If&nbsp;searchwindowsize==-1&nbsp;then&nbsp;the&nbsp;self.<strong>searchwindowsize</strong>&nbsp;value&nbsp;is&nbsp;used.</tt></dd></dl>

<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>

<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&nbsp;File-like&nbsp;<a href="__builtin__.html#object">object</a>.</tt></dd></dl>

<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.<br>
The&nbsp;return&nbsp;value&nbsp;is&nbsp;a&nbsp;tuple&nbsp;of&nbsp;(rows,&nbsp;cols).</tt></dd></dl>

<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<br>
(the&nbsp;human&nbsp;at&nbsp;the&nbsp;keyboard).<br>
Keystrokes&nbsp;are&nbsp;sent&nbsp;to&nbsp;the&nbsp;child&nbsp;process,&nbsp;and&nbsp;the&nbsp;stdout&nbsp;and&nbsp;stderr<br>
output&nbsp;of&nbsp;the&nbsp;child&nbsp;process&nbsp;is&nbsp;printed.<br>
This&nbsp;simply&nbsp;echos&nbsp;the&nbsp;child&nbsp;stdout&nbsp;and&nbsp;child&nbsp;stderr&nbsp;to&nbsp;the&nbsp;real<br>
stdout&nbsp;and&nbsp;it&nbsp;echos&nbsp;the&nbsp;real&nbsp;stdin&nbsp;to&nbsp;the&nbsp;child&nbsp;stdin.<br>
When&nbsp;the&nbsp;user&nbsp;types&nbsp;the&nbsp;escape_character&nbsp;this&nbsp;method&nbsp;will&nbsp;stop.<br>
The&nbsp;default&nbsp;for&nbsp;escape_character&nbsp;is&nbsp;^].&nbsp;This&nbsp;should&nbsp;not&nbsp;be&nbsp;confused<br>
with&nbsp;ASCII&nbsp;27&nbsp;--&nbsp;the&nbsp;ESC&nbsp;character.&nbsp;ASCII&nbsp;29&nbsp;was&nbsp;chosen<br>
for&nbsp;historical&nbsp;merit&nbsp;because&nbsp;this&nbsp;is&nbsp;the&nbsp;character&nbsp;used<br>
by&nbsp;'telnet'&nbsp;as&nbsp;the&nbsp;escape&nbsp;character.&nbsp;The&nbsp;escape_character&nbsp;will<br>
not&nbsp;be&nbsp;sent&nbsp;to&nbsp;the&nbsp;child&nbsp;process.<br>
&nbsp;<br>
You&nbsp;may&nbsp;pass&nbsp;in&nbsp;optional&nbsp;input&nbsp;and&nbsp;output&nbsp;filter&nbsp;functions.<br>
These&nbsp;functions&nbsp;should&nbsp;take&nbsp;a&nbsp;string&nbsp;and&nbsp;return&nbsp;a&nbsp;string.<br>
The&nbsp;output_filter&nbsp;will&nbsp;be&nbsp;passed&nbsp;all&nbsp;the&nbsp;output&nbsp;from&nbsp;the&nbsp;child&nbsp;process.<br>
The&nbsp;input_filter&nbsp;will&nbsp;be&nbsp;passed&nbsp;all&nbsp;the&nbsp;keyboard&nbsp;input&nbsp;from&nbsp;the&nbsp;user.<br>
The&nbsp;input_filter&nbsp;is&nbsp;run&nbsp;BEFORE&nbsp;the&nbsp;check&nbsp;for&nbsp;the&nbsp;escape_character.<br>
&nbsp;<br>
Note&nbsp;that&nbsp;if&nbsp;you&nbsp;change&nbsp;the&nbsp;window&nbsp;size&nbsp;of&nbsp;the&nbsp;parent<br>
the&nbsp;SIGWINCH&nbsp;signal&nbsp;will&nbsp;not&nbsp;be&nbsp;passed&nbsp;through&nbsp;to&nbsp;the&nbsp;child.<br>
If&nbsp;you&nbsp;want&nbsp;the&nbsp;child&nbsp;window&nbsp;size&nbsp;to&nbsp;change&nbsp;when&nbsp;the&nbsp;parent's<br>
window&nbsp;size&nbsp;changes&nbsp;then&nbsp;do&nbsp;something&nbsp;like&nbsp;the&nbsp;following&nbsp;example:<br>
&nbsp;&nbsp;&nbsp;&nbsp;import&nbsp;pexpect,&nbsp;struct,&nbsp;fcntl,&nbsp;termios,&nbsp;signal,&nbsp;sys<br>
&nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;sigwinch_passthrough&nbsp;(sig,&nbsp;data):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;=&nbsp;struct.pack("HHHH",&nbsp;0,&nbsp;0,&nbsp;0,&nbsp;0)<br>
&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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;global&nbsp;p<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p.<a href="#spawn-setwinsize">setwinsize</a>(a[0],a[1])<br>
&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>
&nbsp;&nbsp;&nbsp;&nbsp;signal.signal(signal.SIGWINCH,&nbsp;sigwinch_passthrough)<br>
&nbsp;&nbsp;&nbsp;&nbsp;p.<a href="#spawn-interact">interact</a>()</tt></dd></dl>

<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.<br>
This&nbsp;is&nbsp;non-blocking.&nbsp;If&nbsp;the&nbsp;child&nbsp;was&nbsp;terminated&nbsp;then&nbsp;this<br>
will&nbsp;read&nbsp;the&nbsp;exitstatus&nbsp;or&nbsp;signalstatus&nbsp;of&nbsp;the&nbsp;child.<br>
This&nbsp;returns&nbsp;True&nbsp;if&nbsp;the&nbsp;child&nbsp;process&nbsp;appears&nbsp;to&nbsp;be&nbsp;running&nbsp;or&nbsp;False&nbsp;if&nbsp;not.<br>
It&nbsp;can&nbsp;take&nbsp;literally&nbsp;SECONDS&nbsp;for&nbsp;Solaris&nbsp;to&nbsp;return&nbsp;the&nbsp;right&nbsp;status.</tt></dd></dl>

<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&nbsp;tty(-like)&nbsp;device,&nbsp;else&nbsp;False.</tt></dd></dl>

<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.<br>
In&nbsp;keeping&nbsp;with&nbsp;UNIX&nbsp;tradition&nbsp;it&nbsp;has&nbsp;a&nbsp;misleading&nbsp;name.<br>
It&nbsp;does&nbsp;not&nbsp;necessarily&nbsp;kill&nbsp;the&nbsp;child&nbsp;unless<br>
you&nbsp;send&nbsp;the&nbsp;right&nbsp;signal.</tt></dd></dl>

<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>

<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;<br>
(less&nbsp;if&nbsp;the&nbsp;read&nbsp;hits&nbsp;<a href="#EOF">EOF</a>&nbsp;before&nbsp;obtaining&nbsp;size&nbsp;bytes).&nbsp;<br>
If&nbsp;the&nbsp;size&nbsp;argument&nbsp;is&nbsp;negative&nbsp;or&nbsp;omitted,&nbsp;<br>
read&nbsp;all&nbsp;data&nbsp;until&nbsp;<a href="#EOF">EOF</a>&nbsp;is&nbsp;reached.&nbsp;<br>
The&nbsp;bytes&nbsp;are&nbsp;returned&nbsp;as&nbsp;a&nbsp;string&nbsp;<a href="__builtin__.html#object">object</a>.&nbsp;<br>
An&nbsp;empty&nbsp;string&nbsp;is&nbsp;returned&nbsp;when&nbsp;<a href="#EOF">EOF</a>&nbsp;is&nbsp;encountered&nbsp;immediately.</tt></dd></dl>

<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.<br>
It&nbsp;includes&nbsp;a&nbsp;timeout.&nbsp;If&nbsp;the&nbsp;read&nbsp;does&nbsp;not&nbsp;complete&nbsp;within&nbsp;the<br>
timeout&nbsp;period&nbsp;then&nbsp;a&nbsp;<a href="#TIMEOUT">TIMEOUT</a>&nbsp;exception&nbsp;is&nbsp;raised.<br>
If&nbsp;the&nbsp;end&nbsp;of&nbsp;file&nbsp;is&nbsp;read&nbsp;then&nbsp;an&nbsp;<a href="#EOF">EOF</a>&nbsp;exception&nbsp;will&nbsp;be&nbsp;raised.<br>
If&nbsp;a&nbsp;log&nbsp;file&nbsp;was&nbsp;set&nbsp;using&nbsp;<a href="#spawn-setlog">setlog</a>()&nbsp;then&nbsp;all&nbsp;data&nbsp;will<br>
also&nbsp;be&nbsp;written&nbsp;to&nbsp;the&nbsp;log&nbsp;file.<br>
&nbsp;<br>
If&nbsp;timeout==None&nbsp;then&nbsp;the&nbsp;read&nbsp;may&nbsp;block&nbsp;indefinitely.<br>
If&nbsp;timeout==-1&nbsp;then&nbsp;the&nbsp;self.<strong>timeout</strong>&nbsp;value&nbsp;is&nbsp;used.<br>
If&nbsp;timeout==0&nbsp;then&nbsp;the&nbsp;child&nbsp;is&nbsp;polled&nbsp;and&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;there&nbsp;was&nbsp;no&nbsp;data&nbsp;immediately&nbsp;ready&nbsp;then&nbsp;this&nbsp;will&nbsp;raise&nbsp;a&nbsp;<a href="#TIMEOUT">TIMEOUT</a>&nbsp;exception.<br>
&nbsp;<br>
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&nbsp;character.<br>
This&nbsp;is&nbsp;not&nbsp;effected&nbsp;by&nbsp;the&nbsp;'size'&nbsp;parameter,&nbsp;so&nbsp;if&nbsp;you&nbsp;call<br>
<a href="#spawn-read_nonblocking">read_nonblocking</a>(size=100,&nbsp;timeout=30)&nbsp;and&nbsp;only&nbsp;one&nbsp;character&nbsp;is<br>
available&nbsp;right&nbsp;away&nbsp;then&nbsp;one&nbsp;character&nbsp;will&nbsp;be&nbsp;returned&nbsp;immediately.&nbsp;<br>
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>
&nbsp;<br>
This&nbsp;is&nbsp;a&nbsp;wrapper&nbsp;around&nbsp;os.<a href="#spawn-read">read</a>().<br>
It&nbsp;uses&nbsp;select.select()&nbsp;to&nbsp;implement&nbsp;a&nbsp;timeout.</tt></dd></dl>

<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&nbsp;in<br>
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&nbsp;line.&nbsp;<br>
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&nbsp;because<br>
this&nbsp;is&nbsp;what&nbsp;the&nbsp;pseudo&nbsp;tty&nbsp;device&nbsp;returns.&nbsp;So&nbsp;contrary&nbsp;to&nbsp;what&nbsp;you<br>
may&nbsp;expect&nbsp;you&nbsp;will&nbsp;receive&nbsp;the&nbsp;newline&nbsp;as&nbsp;\r\n.<br>
An&nbsp;empty&nbsp;string&nbsp;is&nbsp;returned&nbsp;when&nbsp;<a href="#EOF">EOF</a>&nbsp;is&nbsp;hit&nbsp;immediately.<br>
Currently,&nbsp;the&nbsp;size&nbsp;agument&nbsp;is&nbsp;mostly&nbsp;ignored,&nbsp;so&nbsp;this&nbsp;behavior&nbsp;is&nbsp;not<br>
standard&nbsp;for&nbsp;a&nbsp;file-like&nbsp;<a href="__builtin__.html#object">object</a>.&nbsp;If&nbsp;size&nbsp;is&nbsp;0&nbsp;then&nbsp;an&nbsp;empty&nbsp;string<br>
is&nbsp;returned.</tt></dd></dl>

<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&nbsp;<br>
the&nbsp;lines&nbsp;thus&nbsp;read.&nbsp;The&nbsp;optional&nbsp;"sizehint"&nbsp;argument&nbsp;is&nbsp;ignored.</tt></dd></dl>

<dl><dt><a name="spawn-send"><strong>send</strong></a>(self, str)</dt><dd><tt>This&nbsp;sends&nbsp;a&nbsp;string&nbsp;to&nbsp;the&nbsp;child&nbsp;process.<br>
This&nbsp;returns&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;written.<br>
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&nbsp;the&nbsp;log.</tt></dd></dl>

<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.<br>
This&nbsp;sends&nbsp;a&nbsp;character&nbsp;which&nbsp;causes&nbsp;the&nbsp;pending&nbsp;parent&nbsp;output<br>
buffer&nbsp;to&nbsp;be&nbsp;sent&nbsp;to&nbsp;the&nbsp;waiting&nbsp;child&nbsp;program&nbsp;without<br>
waiting&nbsp;for&nbsp;end-of-line.&nbsp;If&nbsp;it&nbsp;is&nbsp;the&nbsp;first&nbsp;character&nbsp;of&nbsp;the<br>
line,&nbsp;the&nbsp;<a href="#spawn-read">read</a>()&nbsp;in&nbsp;the&nbsp;user&nbsp;program&nbsp;returns&nbsp;0,&nbsp;which<br>
signifies&nbsp;end-of-file.&nbsp;This&nbsp;means&nbsp;to&nbsp;work&nbsp;as&nbsp;expected&nbsp;<br>
a&nbsp;<a href="#spawn-sendeof">sendeof</a>()&nbsp;has&nbsp;to&nbsp;be&nbsp;called&nbsp;at&nbsp;the&nbsp;begining&nbsp;of&nbsp;a&nbsp;line.&nbsp;<br>
This&nbsp;method&nbsp;does&nbsp;not&nbsp;send&nbsp;a&nbsp;newline.&nbsp;It&nbsp;is&nbsp;the&nbsp;responsibility<br>
of&nbsp;the&nbsp;caller&nbsp;to&nbsp;ensure&nbsp;the&nbsp;eof&nbsp;is&nbsp;sent&nbsp;at&nbsp;the&nbsp;beginning&nbsp;of&nbsp;a&nbsp;line.</tt></dd></dl>

<dl><dt><a name="spawn-sendline"><strong>sendline</strong></a>(self, str<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).<br>
This&nbsp;returns&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;written.</tt></dd></dl>

<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.<br>
Note&nbsp;that&nbsp;anything&nbsp;the&nbsp;child&nbsp;sent&nbsp;before&nbsp;the&nbsp;echo&nbsp;will&nbsp;be&nbsp;lost,&nbsp;so<br>
you&nbsp;should&nbsp;be&nbsp;sure&nbsp;that&nbsp;your&nbsp;input&nbsp;buffer&nbsp;is&nbsp;empty&nbsp;before&nbsp;you&nbsp;setecho.<br>
For&nbsp;example,&nbsp;the&nbsp;following&nbsp;will&nbsp;work&nbsp;as&nbsp;expected.<br>
&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>('cat')<br>
&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>
&nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['1234'])<br>
&nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['1234'])<br>
&nbsp;&nbsp;&nbsp;&nbsp;p.<a href="#spawn-setecho">setecho</a>(False)&nbsp;#&nbsp;Turn&nbsp;off&nbsp;tty&nbsp;echo<br>
&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>
&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>
&nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['abcd'])<br>
&nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['wxyz'])<br>
The&nbsp;following&nbsp;WILL&nbsp;NOT&nbsp;WORK&nbsp;because&nbsp;the&nbsp;lines&nbsp;sent&nbsp;before&nbsp;the&nbsp;setecho<br>
will&nbsp;be&nbsp;lost:<br>
&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="#spawn">spawn</a>('cat')<br>
&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>
&nbsp;&nbsp;&nbsp;&nbsp;p.<a href="#spawn-setecho">setecho</a>(False)&nbsp;#&nbsp;Turn&nbsp;off&nbsp;tty&nbsp;echo<br>
&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>
&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>
&nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['1234'])<br>
&nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['1234'])<br>
&nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['abcd'])<br>
&nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['wxyz'])</tt></dd></dl>

<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>

<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.<br>
I&nbsp;don't&nbsp;like&nbsp;getters&nbsp;and&nbsp;setters&nbsp;without&nbsp;a&nbsp;good&nbsp;reason.</tt></dd></dl>

<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.<br>
This&nbsp;will&nbsp;cause&nbsp;a&nbsp;SIGWINCH&nbsp;signal&nbsp;to&nbsp;be&nbsp;sent&nbsp;to&nbsp;the&nbsp;child.<br>
This&nbsp;does&nbsp;not&nbsp;change&nbsp;the&nbsp;physical&nbsp;window&nbsp;size.<br>
It&nbsp;changes&nbsp;the&nbsp;size&nbsp;reported&nbsp;to&nbsp;TTY-aware&nbsp;applications&nbsp;like<br>
vi&nbsp;or&nbsp;curses&nbsp;--&nbsp;applications&nbsp;that&nbsp;respond&nbsp;to&nbsp;the&nbsp;SIGWINCH&nbsp;signal.</tt></dd></dl>

<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.<br>
It&nbsp;starts&nbsp;nicely&nbsp;with&nbsp;SIGHUP&nbsp;and&nbsp;SIGINT.&nbsp;If&nbsp;"force"&nbsp;is&nbsp;True&nbsp;then<br>
moves&nbsp;onto&nbsp;SIGKILL.<br>
This&nbsp;returns&nbsp;True&nbsp;if&nbsp;the&nbsp;child&nbsp;was&nbsp;terminated.<br>
This&nbsp;returns&nbsp;False&nbsp;if&nbsp;the&nbsp;child&nbsp;could&nbsp;not&nbsp;be&nbsp;terminated.</tt></dd></dl>

<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.<br>
This&nbsp;will&nbsp;not&nbsp;read&nbsp;any&nbsp;data&nbsp;from&nbsp;the&nbsp;child,&nbsp;so&nbsp;this&nbsp;will&nbsp;block&nbsp;forever<br>
if&nbsp;the&nbsp;child&nbsp;has&nbsp;unread&nbsp;output&nbsp;and&nbsp;has&nbsp;terminated.&nbsp;In&nbsp;other&nbsp;words,&nbsp;the&nbsp;child<br>
may&nbsp;have&nbsp;printed&nbsp;output&nbsp;then&nbsp;called&nbsp;exit();&nbsp;but,&nbsp;technically,&nbsp;the&nbsp;child&nbsp;is<br>
still&nbsp;alive&nbsp;until&nbsp;its&nbsp;output&nbsp;is&nbsp;read.</tt></dd></dl>

<dl><dt><a name="spawn-write"><strong>write</strong></a>(self, str)</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>

<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.<br>
The&nbsp;sequence&nbsp;can&nbsp;be&nbsp;any&nbsp;iterable&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;producing&nbsp;strings,&nbsp;<br>
typically&nbsp;a&nbsp;list&nbsp;of&nbsp;strings.&nbsp;This&nbsp;does&nbsp;not&nbsp;add&nbsp;line&nbsp;separators<br>
There&nbsp;is&nbsp;no&nbsp;return&nbsp;value.</tt></dd></dl>

<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dl>

<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'spawn' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;defined)</tt></dl>

</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
    
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<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>)</dt><dd><tt>This&nbsp;function&nbsp;runs&nbsp;the&nbsp;given&nbsp;command;&nbsp;waits&nbsp;for&nbsp;it&nbsp;to&nbsp;finish;<br>
&nbsp;&nbsp;&nbsp;&nbsp;then&nbsp;returns&nbsp;all&nbsp;output&nbsp;as&nbsp;a&nbsp;string.&nbsp;STDERR&nbsp;is&nbsp;included&nbsp;in&nbsp;output.<br>
&nbsp;&nbsp;&nbsp;&nbsp;If&nbsp;the&nbsp;full&nbsp;path&nbsp;to&nbsp;the&nbsp;command&nbsp;is&nbsp;not&nbsp;given&nbsp;then&nbsp;the&nbsp;path&nbsp;is&nbsp;searched.<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;Note&nbsp;that&nbsp;lines&nbsp;are&nbsp;terminated&nbsp;by&nbsp;CR/LF&nbsp;(\r\n)&nbsp;combination<br>
&nbsp;&nbsp;&nbsp;&nbsp;even&nbsp;on&nbsp;UNIX-like&nbsp;systems&nbsp;because&nbsp;this&nbsp;is&nbsp;the&nbsp;standard&nbsp;for&nbsp;pseudo&nbsp;ttys.<br>
&nbsp;&nbsp;&nbsp;&nbsp;If&nbsp;you&nbsp;set&nbsp;withexitstatus&nbsp;to&nbsp;true,&nbsp;then&nbsp;run&nbsp;will&nbsp;return&nbsp;a&nbsp;tuple&nbsp;of<br>
&nbsp;&nbsp;&nbsp;&nbsp;(command_output,&nbsp;exitstatus).&nbsp;If&nbsp;withexitstatus&nbsp;is&nbsp;false&nbsp;then&nbsp;this<br>
&nbsp;&nbsp;&nbsp;&nbsp;returns&nbsp;just&nbsp;command_output.<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;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>
&nbsp;&nbsp;&nbsp;&nbsp;For&nbsp;example,&nbsp;the&nbsp;following&nbsp;code&nbsp;uses&nbsp;<a href="#spawn">spawn</a>:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;pexpect&nbsp;import&nbsp;*<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;child&nbsp;=&nbsp;<a href="#spawn">spawn</a>('scp&nbsp;foo&nbsp;myname@host.example.com:.')<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;child.expect&nbsp;('(?i)password')<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;child.sendline&nbsp;(mypassword)<br>
&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;previous&nbsp;code&nbsp;can&nbsp;be&nbsp;replace&nbsp;with&nbsp;the&nbsp;following,&nbsp;which&nbsp;you&nbsp;may<br>
&nbsp;&nbsp;&nbsp;&nbsp;or&nbsp;may&nbsp;not&nbsp;find&nbsp;simpler:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;pexpect&nbsp;import&nbsp;*<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;run&nbsp;('scp&nbsp;foo&nbsp;myname@host.example.com:.',&nbsp;events={'(?i)password':&nbsp;mypassword})<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;Examples:<br>
&nbsp;&nbsp;&nbsp;&nbsp;Start&nbsp;the&nbsp;apache&nbsp;daemon&nbsp;on&nbsp;the&nbsp;local&nbsp;machine:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;pexpect&nbsp;import&nbsp;*<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;run&nbsp;("/usr/local/apache/bin/apachectl&nbsp;start")<br>
&nbsp;&nbsp;&nbsp;&nbsp;Check&nbsp;in&nbsp;a&nbsp;file&nbsp;using&nbsp;SVN:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;pexpect&nbsp;import&nbsp;*<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;run&nbsp;("svn&nbsp;ci&nbsp;-m&nbsp;'automatic&nbsp;commit'&nbsp;my_file.py")<br>
&nbsp;&nbsp;&nbsp;&nbsp;Run&nbsp;a&nbsp;command&nbsp;and&nbsp;capture&nbsp;exit&nbsp;status:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;pexpect&nbsp;import&nbsp;*<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(command_output,&nbsp;exitstatus)&nbsp;=&nbsp;run&nbsp;('ls&nbsp;-l&nbsp;/bin',&nbsp;withexitstatus=1)<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;Tricky&nbsp;Examples:&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;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.<br>
&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;run&nbsp;("ssh&nbsp;username@machine.example.com&nbsp;'ls&nbsp;-l'",&nbsp;events={'(?i)password':'secret<br>
'})<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;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>
&nbsp;&nbsp;&nbsp;&nbsp;progress&nbsp;ticks&nbsp;every&nbsp;5&nbsp;seconds&nbsp;as&nbsp;it&nbsp;runs.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;pexpect&nbsp;import&nbsp;*<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;print_ticks(d):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;d['event_count'],<br>
&nbsp;&nbsp;&nbsp;&nbsp;&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>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;'events'&nbsp;argument&nbsp;should&nbsp;be&nbsp;a&nbsp;dictionary&nbsp;of&nbsp;patterns&nbsp;and&nbsp;responses.<br>
&nbsp;&nbsp;&nbsp;&nbsp;Whenever&nbsp;one&nbsp;of&nbsp;the&nbsp;patterns&nbsp;is&nbsp;seen&nbsp;in&nbsp;the&nbsp;command&nbsp;out<br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#-run">run</a>()&nbsp;will&nbsp;send&nbsp;the&nbsp;associated&nbsp;response&nbsp;string.&nbsp;Note&nbsp;that&nbsp;you&nbsp;should<br>
&nbsp;&nbsp;&nbsp;&nbsp;put&nbsp;newlines&nbsp;in&nbsp;your&nbsp;string&nbsp;if&nbsp;Enter&nbsp;is&nbsp;necessary.<br>
&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;responses&nbsp;may&nbsp;also&nbsp;contain&nbsp;callback&nbsp;functions.<br>
&nbsp;&nbsp;&nbsp;&nbsp;Any&nbsp;callback&nbsp;is&nbsp;function&nbsp;that&nbsp;takes&nbsp;a&nbsp;dictionary&nbsp;as&nbsp;an&nbsp;argument.<br>
&nbsp;&nbsp;&nbsp;&nbsp;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<br>
&nbsp;&nbsp;&nbsp;&nbsp;you&nbsp;can&nbsp;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<br>
&nbsp;&nbsp;&nbsp;&nbsp;in&nbsp;<a href="#-run">run</a>()&nbsp;(event_count,&nbsp;child,&nbsp;and&nbsp;extra_args&nbsp;are&nbsp;the&nbsp;most&nbsp;useful).<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;callback&nbsp;may&nbsp;return&nbsp;True&nbsp;to&nbsp;stop&nbsp;the&nbsp;current&nbsp;run&nbsp;process&nbsp;otherwise<br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#-run">run</a>()&nbsp;continues&nbsp;until&nbsp;the&nbsp;next&nbsp;event.<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;callback&nbsp;may&nbsp;also&nbsp;return&nbsp;a&nbsp;string&nbsp;which&nbsp;will&nbsp;be&nbsp;sent&nbsp;to&nbsp;the&nbsp;child.<br>
&nbsp;&nbsp;&nbsp;&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&nbsp;pass&nbsp;data&nbsp;to<br>
&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;callback&nbsp;function&nbsp;through&nbsp;<a href="#-run">run</a>()&nbsp;through&nbsp;the&nbsp;locals&nbsp;dictionary&nbsp;passed&nbsp;to&nbsp;a&nbsp;callback.</tt></dd></dl>
 <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.<br>
It&nbsp;splits&nbsp;arguments&nbsp;on&nbsp;spaces,&nbsp;but&nbsp;handles<br>
embedded&nbsp;quotes,&nbsp;doublequotes,&nbsp;and&nbsp;escaped&nbsp;characters.<br>
It's&nbsp;impossible&nbsp;to&nbsp;do&nbsp;this&nbsp;with&nbsp;a&nbsp;regular&nbsp;expression,&nbsp;so<br>
I&nbsp;wrote&nbsp;a&nbsp;little&nbsp;state&nbsp;machine&nbsp;to&nbsp;parse&nbsp;the&nbsp;command&nbsp;line.</tt></dd></dl>
 <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;&nbsp;<br>
then&nbsp;checks&nbsp;if&nbsp;it&nbsp;is&nbsp;executable.<br>
This&nbsp;returns&nbsp;the&nbsp;full&nbsp;path&nbsp;to&nbsp;the&nbsp;filename&nbsp;if&nbsp;found&nbsp;and&nbsp;executable.<br>
Otherwise&nbsp;this&nbsp;returns&nbsp;None.</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
    
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>__all__</strong> = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn', 'run', 'which', 'split_command_line', '__version__', '__revision__']<br>
<strong>__revision__</strong> = '$Revision: 395 $'<br>
<strong>__version__</strong> = '2.1'</td></tr></table>
</body></html>