if {[file exists "./abc.test"]} {send "cat ./abc.txt\r"}
...seems to check for file existence on the machine expect runs on, not the remote one. So unless the script is being run on the remote server, it won't work.
Hm, you're probably doing things in a rather roundabout way.
First, please describe your context:
Exactly how (complete command line) do you invoke this script?
How does it access the remote server? There is no remote access in the script you provide.
Finally, what are you really trying to do? If you want to print a file on a remote system, it's probably easier to directly invoke ssh. Expect is meant for scripting programs which do not have a scripting language (such as simple ftp clients). It's needlessly complicated to use it with a command shell, which already has a powerful scripting language.
I have never used Expect, but your code sample...
...seems to check for file existence on the machine expect runs on, not the remote one. So unless the script is being run on the remote server, it won't work.
Here is what I did and it worked now
This way, the file gets printed if it exists and does not throw an error if it doesn't.
Hm, you're probably doing things in a rather roundabout way.
First, please describe your context:
Finally, what are you really trying to do? If you want to print a file on a remote system, it's probably easier to directly invoke ssh. Expect is meant for scripting programs which do not have a scripting language (such as simple ftp clients). It's needlessly complicated to use it with a command shell, which already has a powerful scripting language.