-
Start a terminal, run
tty
to get its device file name, "/dev/pts/0" in this case. -
Start another terminal. Create a expect script "testDebug.exp":
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/usr/bin/expect set prompt "\\\[hadoop@49server\\s.*\\\]\\\$\\s" spawn telnet 10.0.2.49 exp_internal 1 expect "login:" send "hadoop\r" expect "Password:" send "h\r" expect -re $prompt send "df -h\r" expect -re $prompt send "exit\r" expect eof
-
Give execution priority to testDebug.exp (using chmod) and run it:
./testDebug.exp 2> /dev/pts/0
. You can see all diagnostics information are printed in the terminal "/dev/pts/0" while all "normal" informal are printed in the second terminal window.
Explanation: the command "exp_internal 1" send all pattern diagnostics to standard error, which is specified as "2> ..." in the command line. Meanwhile, a terminal's id can be get from "tty" command.
You can use "exp_internal -f
Reference: Section "Enabling Internal Diagnostics" and "Logging Internal Diagnostics" in chapter 7:"Debugging Patterns And Controlling Output" of "Exploring Expect" by Don Libes.
Notes: If you run command "ls -l /dev/pts/*", you can get the following outputs:
crw--w---- 1 lichao tty 136, 0 Aug 28 11:56 0
...
Notice that the file type are "c" (the first character of the line), which stands for "character device" (standard input/output, like keyboard and screen, relative to "block device", like hard drives). See "http://en.wikipedia.org/wiki/Unix_file_types#Device_file" for details.