expect_out(buffer)
时间: 2023-09-15 21:21:00 浏览: 50
expect_out(buffer) is a variable in the Expect scripting language. It contains the output that was matched by the last "expect" command. This variable can be used to capture and process the output of the command being executed.
For example, let's say we want to automate the process of logging into a remote server using SSH. We can use the "expect" command to wait for certain output from the server, such as the login prompt, and then send the username and password:
```
#!/usr/bin/expect
set timeout 10
spawn ssh username@remote_server
expect "password:"
send "password\r"
expect "$ "
send "ls -la\r"
expect "$ "
puts $expect_out(buffer)
send "exit\r"
expect eof
```
In this script, we wait for the "password:" prompt, and then send the password. We then wait for the shell prompt "$ ", and send the command "ls -la". The output of that command is stored in the expect_out(buffer) variable, which we print to the console. Finally, we exit the SSH session.