要在Ubuntu上使用expect脚本读取外部文件,可以使用以下步骤:
创建一个包含所需输入的外部文件,例如input.txt。
编写一个expect脚本,使用spawn命令启动需要输入的程序,并使用expect命令读取外部文件中的输入。
例如,假设我们有一个需要输入用户名和密码的程序,并且我们想使用input.txt文件中的用户名和密码。以下是一个示例expect脚本:
#!/usr/bin/expectset input_file "input.txt"set file [open $input_file r]gets $file usernamegets $file passwordclose $filespawn ./your_programexpect "Enter username:"send "$username\r"expect "Enter password:"send "$password\r"interact保存并运行上述expect脚本,确保将your_program替换为您要运行的实际程序。这样,expect脚本将读取外部文件中的用户名和密码,并将其发送到需要输入的程序中。


