hi i have following expect script named a.exp
#!/usr/bin/expect
spawn cat a.txt
where a.txt contains the following single line of string text
Hello World
next i made it executable by using the following command
chmod +x a.exp
now, i run it as follows
./a.exp
the output i get is as follows
spawn cat a.txt
on the other hand if i use the the following script
puts [exec cat a.txt]
instead of
spawn cat a.txt
it does print the contents of the a.txt file. plz can you help me to execute it using the spawn? thanks!
You’ve not told it to read anything from the spawned program. If I use this version of
a.expit gets what I believe to be the correct output:If you’re really just wanting to pull in everything that the other program writes out without sending anything in return, you use this last line instead to wait for end-of-file:
Both produce exactly this output when I test: