I have an expect script which checks if a file exists on a remote server and then tries to print ( using cat) it if it does
For some reason the expect script ignores these commands.
send "if {[file exists "./abc.test"]} {cat ./abc.txt\r}"
I have never used Expect, but your code sample...
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.
Here is what I did and it worked now
cat /some/path/abc.txt 2> /dev/null
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.