386:. They were built to service the users administering the product, but the company often does not spend the resources to fully implement a robust scripting language. An Expect script can spawn a shell, look up environmental variables, perform some Unix commands to retrieve more information, and then enter into the product's command-line interface armed with the necessary information to achieve the user's goal. After retrieving information by interacting with the product via its command-line interface, the script can make intelligent decisions about what action to take, if any.
39:
341:
389:
Every time an Expect operation is completed, the results are stored in a local variable called $ expect_out. This allows the script to harvest information to feedback to the user, and it also allows conditional behavior of what to send next based on the circumstances.
404:
Expect script can be automated using a tool called 'autoexpect'. This tool observes your actions and generates an Expect script using heuristics. Though generated code may be large and somewhat cryptic, one can always tweak the generated script to get the exact code.
378:
Expect serves as a "glue" to link existing utilities together. The general idea is to figure out how to make Expect use the system's existing tools rather than figure out how to solve a problem inside of Expect.
1678:
382:
A key usage of Expect involves commercial software products. Many of these products provide some type of command-line interface, but these usually lack the power needed to write
1486:
1006:". You can, however, add code that will prompt you for your password rather than giving your password as an argument. This should be more secure. See the example below.
1718:
319:(Unix) or emulates a console (Windows), starts the target program, and then communicates with it, just as a human would, via the terminal or console interface.
1002:
Using passwords as command-line arguments, like in this example, is a huge security hole, as any other user on the machine can read this password by running "
1703:
1560:
1496:
351:
1576:
1621:
1535:
122:
1331: - a Java implementation of the Expect tool, but supports nested closures. There is also wrapper for Groovy language DSL.
1550:
1513:
1196:
383:
60:
1366:
1216:
884:"Usage: <user> <passw> <host> <location> <file1 to send> <file2 to send>\n"
1708:
1698:
1204:
1640:
1220:
1208:
1200:
167:
103:
1395:
75:
49:
1228:
1449: โ Expect for shells. It's implemented in the client/server model which also supports attach/detach (like
1307:โ a pure Java 1.6+ implementation of the Expect tool. It is designed to be simple, easy to use and extensible.
1240:
196:
82:
398:
56:
1713:
1231:. These are generally not exact clones of the original Expect, but the concepts tend to be very similar.
89:
19:
This article is about the Unix tool. For a definition of the term "expect", see the
Wiktionary entry
1281: - an Expect-like Go language library to automate control of terminal or console based programs.
284:
71:
393:
A common use of Expect is to set up a testing suite for programs, utilities or embedded systems.
308:
1617:
1613:
1556:
1529:
1492:
1472:"Expect FAQ: Our company policy requires a license to use Expect. Where can we get a license?"
272:
212:
296:
219:
203:
1682:
316:
397:
is a testing suite written using Expect for use in testing. It has been used for testing
991:"\nError connecting to server: $ host, user: $ user and password: $ passw!\n"
320:
27:
1692:
1646:
1606:
264:
224:
96:
1382:
1224:
312:
1634:
1443: โ expect-like utility to run interactive commands in the Unix shell-scripts
1291:
1195:
Various projects implement Expect-like functionality in other languages, such as
1673:
1322:
38:
1398: โ a drop in replacement for the expect.rb module in the standard library.
1328:
1450:
1304:
153:
141:
1378:
1341:
1471:
1003:
260:
146:
1669:
1427:
1246:
1372:
1430: โ a Scala implementation of a very small subset of the Expect tool.
1577:"Tcl/Tk in the Development of User-Extensible Graphical User Interfaces"
20:
1446:
1401:
1278:
394:
1608:
Exploring Expect: A Tcl-Based Tool for
Automating Interactive Programs
1485:
Nemeth, Evi; Snyder, Garth; Seebass, Scott; Hein, Trent (2000-08-29).
1310:
1362:
1272:
304:
288:
1662:
235:
1414:
599:# Switch to binary mode, and then wait for an 'ftp' prompt.
1349:
1316:
208:
1262:- test automation framework with Expect style execution commands.
263:. The program automates interactions with programs that expose a
1369:
module for controlling interactive programs in a pseudo-terminal
1345:
1212:
300:
268:
1440:
584:# Send the password, and then wait for an 'ftp' prompt.
1404: โ Interact with Cisco IOS, IOS-XR, and Juniper JUNOS CLI
1259:
1249: โ An Expect-inspired console automation library for .NET
670:# Procedure to attempt connecting; result 0 if OK, 1 otherwise
334:
324:
292:
256:
32:
662:
Below is an example that automates SFTP (with a password):
531:# For example, the file size is indeed big and the network
483:# Capture the results of the command into a variable. This
410:# Assume $ remote_server, $ my_user_id, $ my_password, and
1514:"Automate Inputs to Linux Scripts With the expect Command"
1066:
Another example of automated SSH login to a user machine:
1635:"Advanced Programming in Expect: A Bulletproof Interface"
1313: โ an attempt at a Java clone of the original Expect
569:# Send the username, and then wait for a password prompt.
534:# speed is really one problem, you'd better set this
435:# Send the username, and then wait for a password prompt.
1381: โ A Python expect-like extension for the Paramiko
1319: โ a Java implementation of the Unix expect utility
358:
267:
interface. Expect, originally written in 1990 for the
1071:# Timeout is a predefined variable in Expect which by
450:# Send the password, and then wait for a shell prompt.
416:# Open a Telnet session to a remote server, and wait
1549:
Carling, M.; Degler, Stephen; Dennis, James (2000).
1294: - a Groovy DSL implementation of Expect tool.
1077:# spawn_id is another predefined variable in Expect.
1417: - pexpect-like package for the Rust language.
1325: โ pure Java implementation of the Expect tool
230:
218:
202:
192:
166:
152:
140:
63:. Unsourced material may be challenged and removed.
1605:
505:# Exit the Telnet session, and wait for a special
323:, another Tcl extension, can be used to provide a
283:Expect is used to automate control of interactive
1679:When to use Expect scripting and when to avoid it
1080:# It is a good practice to close spawn_id handle
401:and remote targets such as embedded development.
523:Another example is a script that automates FTP:
1685: (archived 2017-10-25) (IBM Developerworks)
1375: โ port of pexpect to the Windows platform
1275: - Expect-like package for the Go language
644:# Exit the FTP session, and wait for a special
413:# $ my_command were read earlier in the script.
550:# Open an FTP session to a remote server, and
26:For the South Korean professional gamer, see
8:
135:
896:# Sftp to specified host and send the files
465:# Send the prebuilt command, and then wait
1243: โ Expect functionality for C# (.NET)
528:# Set timeout parameter to a proper value.
134:
1385:library which also supports tailing logs.
271:platform, has since become available for
123:Learn how and when to remove this message
1719:Public-domain software with source code
1463:
788:#puts "location: $ location";
486:# can be displayed, or written to disk.
16:Extension to the Tcl scripting language
1527:
7:
1128:"The authenticity of host"
61:adding citations to reliable sources
1488:UNIX System Administration Handbook
776:#puts "Argument data:\n";
14:
1641:Linux Documentation Project (LDP)
794:#puts "file2: $ file2";
791:#puts "file1: $ file1";
782:#puts "passw: $ passw";
361:and remove advice or instruction.
1639:Linux Gazette, (a member of the
339:
173:5.45.4 / 4 February 2018
37:
1704:Free software programmed in Tcl
1074:# default is set to 10 seconds.
785:#puts "host: $ host";
779:#puts "user: $ user";
48:needs additional citations for
1512:Mckay, David (May 24, 2021) .
259:scripting language written by
1:
1534:: CS1 maint: date and year (
553:# wait for a username prompt.
1645:. No. 48. issue of the
1024:"Enter Password: "
797:# Check if all were provided
1552:Linux System Administration
1083:# created by spawn command.
938:"cd $ location\r"
749:# Read the input parameters
590:"$ my_password\r"
468:# for another shell prompt.
456:"$ my_password\r"
1735:
1348:module (newest version at
575:"$ my_user_id\r"
474:"$ my_command\r"
441:"$ my_user_id\r"
315:, and others. Expect uses
25:
18:
960:"put $ file1\r"
954:"put $ file2\r"
188:
162:
1152:"$ password\r"
1068:
1008:
667:#!/usr/bin/env expect -f
664:
647:# end-of-file character.
525:
508:# end-of-file character.
419:# for a username prompt.
407:
255:is an extension to the
1633:Fisher, David (1999).
1491:. Pearson Education.
1143:"password:"
704:"$ passw\r"
695:"Password:"
614:# Turn off prompting.
581:"password:"
566:"username:"
447:"password:"
432:"username:"
175:; 6 years ago
635:"mget *\r"
620:"prompt\r"
537:# parameter a value.
359:rewrite this section
57:improve this article
1709:Automation software
1699:Scripting languages
1604:Libes, Don (1995).
1555:. Sams Publishing.
966:"ls -l\r"
641:"ftp>"
629:# Get all the files
626:"ftp>"
611:"ftp>"
596:"ftp>"
275:and other systems.
137:
1167:"exit\r"
1034:"(.*)\n"
972:"quit\r"
514:"exit\r"
142:Original author(s)
1562:978-1-56205-934-7
1498:978-0-13-700291-7
1137:"yes\r"
713:"sftp*"
653:"bye\r"
605:"bin\r"
376:
375:
352:a manual or guide
273:Microsoft Windows
250:
249:
133:
132:
125:
107:
1726:
1666:
1665:
1663:Official website
1650:
1627:
1611:
1591:
1590:
1588:
1587:
1573:
1567:
1566:
1546:
1540:
1539:
1533:
1525:
1523:
1521:
1516:. category/Linux
1509:
1503:
1502:
1482:
1476:
1475:
1468:
1186:
1183:
1180:
1177:
1174:
1171:
1168:
1165:
1162:
1159:
1156:
1153:
1150:
1147:
1144:
1141:
1138:
1135:
1132:
1129:
1126:
1123:
1120:
1117:
1114:
1111:
1108:
1105:
1102:
1098:
1094:
1091:
1087:
1084:
1081:
1078:
1075:
1072:
1062:
1058:
1055:
1052:
1048:
1044:
1041:
1038:
1035:
1031:
1028:
1025:
1022:
1019:
1015:
1012:
998:
995:
992:
989:
986:
983:
980:
976:
973:
970:
967:
964:
961:
958:
955:
952:
949:
946:
942:
939:
936:
933:
930:
927:
924:
921:
918:
915:
911:
908:
904:
900:
897:
894:
891:
888:
885:
882:
879:
876:
873:
870:
867:
864:
861:
858:
855:
852:
849:
846:
843:
840:
837:
834:
831:
828:
825:
822:
819:
816:
813:
810:
807:
804:
801:
798:
795:
792:
789:
786:
783:
780:
777:
773:
769:
765:
761:
757:
753:
750:
747:
744:
741:
738:
735:
732:
729:
726:
723:
720:
717:
714:
711:
708:
705:
702:
699:
696:
693:
690:
687:
684:
681:
678:
674:
671:
668:
657:
654:
651:
648:
645:
642:
639:
636:
633:
630:
627:
624:
621:
618:
615:
612:
609:
606:
603:
600:
597:
594:
591:
588:
585:
582:
579:
576:
573:
570:
567:
564:
561:
557:
554:
551:
548:
545:
541:
538:
535:
532:
529:
518:
515:
512:
509:
506:
503:
500:
497:
494:
490:
487:
484:
481:
478:
475:
472:
469:
466:
463:
460:
457:
454:
451:
448:
445:
442:
439:
436:
433:
430:
427:
423:
420:
417:
414:
411:
371:
368:
362:
350:is written like
343:
342:
335:
317:pseudo terminals
246:
243:
241:
239:
237:
204:Operating system
183:
181:
176:
138:
128:
121:
117:
114:
108:
106:
65:
41:
33:
1734:
1733:
1729:
1728:
1727:
1725:
1724:
1723:
1689:
1688:
1683:Wayback Machine
1661:
1660:
1657:
1632:
1624:
1603:
1600:
1598:Further reading
1595:
1594:
1585:
1583:
1575:
1574:
1570:
1563:
1548:
1547:
1543:
1526:
1519:
1517:
1511:
1510:
1506:
1499:
1484:
1483:
1479:
1470:
1469:
1465:
1460:
1437:
1424:
1411:
1392:
1379:paramiko-expect
1359:
1338:
1323:Expect-for-Java
1301:
1288:
1269:
1256:
1237:
1193:
1188:
1187:
1184:
1181:
1178:
1175:
1172:
1169:
1166:
1163:
1160:
1158:"*\]"
1157:
1154:
1151:
1148:
1145:
1142:
1139:
1136:
1133:
1130:
1127:
1124:
1121:
1118:
1115:
1112:
1109:
1106:
1103:
1100:
1096:
1092:
1089:
1085:
1082:
1079:
1076:
1073:
1070:
1064:
1063:
1060:
1056:
1053:
1050:
1046:
1042:
1039:
1036:
1033:
1029:
1026:
1023:
1020:
1017:
1013:
1010:
1000:
999:
996:
993:
990:
987:
984:
981:
978:
974:
971:
968:
965:
962:
959:
956:
953:
950:
947:
944:
940:
937:
934:
931:
928:
925:
922:
919:
916:
913:
909:
906:
902:
898:
895:
892:
889:
886:
883:
880:
877:
874:
871:
868:
865:
862:
859:
856:
853:
850:
847:
844:
841:
838:
835:
832:
829:
826:
823:
820:
817:
814:
811:
808:
805:
802:
799:
796:
793:
790:
787:
784:
781:
778:
775:
771:
767:
763:
759:
755:
751:
748:
745:
742:
739:
736:
733:
730:
727:
724:
721:
718:
715:
712:
709:
706:
703:
700:
697:
694:
691:
688:
685:
682:
679:
676:
672:
669:
666:
660:
659:
655:
652:
649:
646:
643:
640:
637:
634:
631:
628:
625:
622:
619:
616:
613:
610:
607:
604:
601:
598:
595:
592:
589:
586:
583:
580:
577:
574:
571:
568:
565:
562:
560:$ remote_server
559:
555:
552:
549:
546:
543:
539:
536:
533:
530:
527:
521:
520:
516:
513:
510:
507:
504:
501:
498:
495:
492:
488:
485:
482:
479:
476:
473:
470:
467:
464:
461:
458:
455:
452:
449:
446:
443:
440:
437:
434:
431:
428:
426:$ remote_server
425:
421:
418:
415:
412:
409:
372:
366:
363:
356:
344:
340:
333:
281:
234:
184:
179:
177:
174:
129:
118:
112:
109:
66:
64:
54:
42:
31:
24:
17:
12:
11:
5:
1732:
1730:
1722:
1721:
1716:
1711:
1706:
1701:
1691:
1690:
1687:
1686:
1676:
1667:
1656:
1655:External links
1653:
1652:
1651:
1629:
1628:
1622:
1614:O'Reilly Media
1599:
1596:
1593:
1592:
1581:www.usenix.org
1568:
1561:
1541:
1504:
1497:
1477:
1462:
1461:
1459:
1456:
1455:
1454:
1444:
1436:
1433:
1432:
1431:
1423:
1420:
1419:
1418:
1410:
1407:
1406:
1405:
1399:
1391:
1388:
1387:
1386:
1376:
1370:
1358:
1355:
1354:
1353:
1337:
1334:
1333:
1332:
1326:
1320:
1314:
1308:
1300:
1297:
1296:
1295:
1287:
1284:
1283:
1282:
1276:
1268:
1265:
1264:
1263:
1255:
1252:
1251:
1250:
1244:
1236:
1233:
1192:
1189:
1069:
1040:"\n"
1009:
665:
526:
408:
374:
373:
347:
345:
338:
332:
329:
280:
277:
248:
247:
232:
228:
227:
222:
216:
215:
206:
200:
199:
194:
190:
189:
186:
185:
172:
170:
168:Stable release
164:
163:
160:
159:
156:
150:
149:
144:
131:
130:
45:
43:
36:
28:Expect (gamer)
15:
13:
10:
9:
6:
4:
3:
2:
1731:
1720:
1717:
1715:
1714:Tk (software)
1712:
1710:
1707:
1705:
1702:
1700:
1697:
1696:
1694:
1684:
1680:
1677:
1675:
1671:
1668:
1664:
1659:
1658:
1654:
1648:
1647:Linux Gazette
1644:
1642:
1636:
1631:
1630:
1625:
1623:1-565-92090-2
1619:
1615:
1610:
1609:
1602:
1601:
1597:
1582:
1578:
1572:
1569:
1564:
1558:
1554:
1553:
1545:
1542:
1537:
1531:
1515:
1508:
1505:
1500:
1494:
1490:
1489:
1481:
1478:
1474:. 2006-10-11.
1473:
1467:
1464:
1457:
1452:
1448:
1445:
1442:
1439:
1438:
1434:
1429:
1426:
1425:
1421:
1416:
1413:
1412:
1408:
1403:
1400:
1397:
1394:
1393:
1389:
1384:
1380:
1377:
1374:
1371:
1368:
1364:
1361:
1360:
1356:
1351:
1347:
1343:
1340:
1339:
1335:
1330:
1327:
1324:
1321:
1318:
1315:
1312:
1309:
1306:
1303:
1302:
1298:
1293:
1292:expect4groovy
1290:
1289:
1285:
1280:
1277:
1274:
1271:
1270:
1266:
1261:
1258:
1257:
1253:
1248:
1245:
1242:
1239:
1238:
1234:
1232:
1230:
1226:
1222:
1218:
1214:
1210:
1206:
1202:
1198:
1190:
1067:
1007:
1005:
663:
524:
480:"%"
462:"%"
406:
402:
400:
396:
391:
387:
385:
380:
370:
367:December 2020
360:
355:
353:
348:This section
346:
337:
336:
330:
328:
326:
322:
318:
314:
310:
306:
302:
298:
294:
290:
286:
278:
276:
274:
270:
266:
265:text terminal
262:
258:
254:
245:
233:
229:
226:
225:Public domain
223:
221:
217:
214:
210:
207:
205:
201:
198:
195:
191:
187:
171:
169:
165:
161:
157:
155:
151:
148:
145:
143:
139:
127:
124:
116:
105:
102:
98:
95:
91:
88:
84:
81:
77:
74: โ
73:
69:
68:Find sources:
62:
58:
52:
51:
46:This article
44:
40:
35:
34:
29:
22:
1638:
1607:
1584:. Retrieved
1580:
1571:
1551:
1544:
1518:. Retrieved
1507:
1487:
1480:
1466:
1428:scala-expect
1350:metacpan.org
1247:DotNetExpect
1194:
1191:Alternatives
1065:
1051:$ expect_out
1001:
872:""
860:""
848:""
836:""
824:""
812:""
661:
522:
493:$ expect_out
403:
392:
388:
381:
377:
364:
357:Please help
349:
285:applications
282:
252:
251:
158:Nils Carlson
154:Developer(s)
119:
110:
100:
93:
86:
79:
67:
55:Please help
50:verification
47:
1674:SourceForge
1329:expect4java
1027:expect_user
737:# Timed out
1693:Categories
1586:2022-08-11
1458:References
1451:GNU screen
1373:winpexpect
1241:Expect.NET
1185:$ spawn_id
842:$ location
193:Written in
180:2018-02-04
83:newspapers
1342:Expect.pm
1279:go-expect
1099:@machine
1037:send_user
1018:send_user
766:location
261:Don Libes
238:.tcl-lang
147:Don Libes
1530:cite web
1402:Expect4r
1365: โ
1344: โ
1311:expect4j
1305:ExpectIt
1273:GoExpect
287:such as
113:May 2017
72:"Expect"
1681:at the
1520:Nov 28,
1447:sexpect
1415:rexpect
1396:RExpect
1363:Pexpect
1317:ExpectJ
1125:{break}
1088:timeout
1059:,string
943:timeout
866:$ file2
854:$ file1
818:$ passw
675:connect
542:timeout
491:results
395:DejaGnu
384:scripts
242:/expect
231:Website
220:License
213:Windows
178: (
97:scholar
1670:Expect
1620:
1559:
1495:
1367:Python
1357:Python
1286:Groovy
1254:Erlang
1217:Python
1209:Groovy
1116:expect
1097:$ user
975:expect
907:$ host
903:$ user
830:$ host
806:$ user
774:file2
770:file1
758:passw
740:return
719:return
707:expect
689:expect
656:expect
638:expect
623:expect
608:expect
593:expect
578:expect
563:expect
517:expect
499:buffer
477:expect
459:expect
444:expect
429:expect
424:telnet
305:rlogin
297:passwd
289:Telnet
279:Basics
253:Expect
136:Expect
99:
92:
85:
78:
70:
21:expect
1441:Empty
1435:Shell
1422:Scala
1225:Shell
1205:Scala
1182:close
1101:while
1093:spawn
1045:echo
1016:echo
920:$ rez
899:spawn
762:host
754:user
680:passw
556:spawn
422:spawn
331:Usage
209:POSIX
104:JSTOR
90:books
1618:ISBN
1557:ISBN
1536:link
1522:2023
1493:ISBN
1409:Rust
1390:Ruby
1346:Perl
1336:Perl
1299:Java
1227:and
1221:Ruby
1213:Perl
1201:Java
1179:wait
1164:send
1149:send
1134:send
1049:PASS
1043:stty
1011:stty
994:exit
988:puts
979:exit
977:eof
969:send
963:send
957:send
951:send
935:send
912:rez
901:sftp
887:exit
881:puts
701:send
673:proc
658:eof
650:send
632:send
617:send
602:send
587:send
572:send
519:eof
511:send
471:send
453:send
438:send
301:fsck
269:Unix
240:.org
236:core
76:news
1672:on
1383:SSH
1260:lux
1122:eof
1095:ssh
1086:set
1047:set
941:set
910:set
772:set
768:set
764:set
760:set
756:set
752:set
558:ftp
540:set
489:set
399:GCC
325:GUI
313:SSH
309:tip
293:FTP
257:Tcl
59:by
1695::
1637:.
1616:.
1612:.
1579:.
1532:}}
1528:{{
1453:).
1267:Go
1235:C#
1229:Go
1223:,
1219:,
1215:,
1211:,
1207:,
1203:,
1199:,
1197:C#
1090:60
1032:re
1021:--
1004:ps
923:==
914:if
869:==
863:||
857:==
851:||
845:==
839:||
833:==
827:||
821:==
815:||
809:==
800:if
327:.
321:Tk
311:,
307:,
303:,
299:,
295:,
291:,
211:,
1649:.
1643:)
1626:.
1589:.
1565:.
1538:)
1524:.
1501:.
1352:)
1176:}
1173:}
1170:}
1161:{
1155:}
1146:{
1140:}
1131:{
1119:{
1113:{
1110:}
1107:1
1104:{
1061:)
1057:1
1054:(
1030:-
1014:-
997:1
985:}
982:0
948:1
945:-
932:{
929:}
926:0
917:{
905:@
893:}
890:1
878:{
875:}
803:{
746:}
743:1
734:}
731:}
728:}
725:}
722:0
716:{
710:{
698:{
692:{
686:{
683:}
677:{
547:1
544:-
502:)
496:(
369:)
365:(
354:.
244:/
197:C
182:)
126:)
120:(
115:)
111:(
101:ยท
94:ยท
87:ยท
80:ยท
53:.
30:.
23:.
Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.