0

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!

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
asil2
  • 3
  • 1
  • 3

1 Answers1

4

You've not told it to read anything from the spawned program. If I use this version of a.exp it gets what I believe to be the correct output:

#!/usr/bin/expect
spawn cat a.txt
expect "\n";        # Wait for a newline

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:

expect eof

Both produce exactly this output when I test:

spawn cat a.txt
Hello World
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215