我正在学习如何使用 Linux 命令 - 期望遵循本教程。
#!/usr/bin/expect
set timeout 20
spawn "./addition.pl"
expect "Enter the number1 :" { send "12\r" }
expect "Enter the number2 :" { send "23\r" }
interact
任何人都可以在这里解释以下命令的作用。
spawn "./addition.pl"
顺便说一句,我找不到任何名为“./additon.pl”的文件,所以我无法成功运行该示例。
我不知道这个 Perl 是如何编写的,但我想脚本(正如 jvperrin 提到的,它可以是任何语言)应该从标准输入中读取并将它们相加。我使用 Python 并尝试编写 adder.py。
#!/usr/bin/python
import sys
print int(sys.argv[1]) + int(sys.argv[2])
但是当我改变 spawn "./add.py" 它仍然不起作用......
错误如下所示:
Traceback (most recent call last):
File "./add.py", line 3, in <module>
print int(sys.argv[1]) + int(sys.argv[2])
IndexError: list index out of range
expect: spawn id exp7 not open
while executing
"expect "Enter the number2 :" { send "23\r" }"
(file "./test" line 8)