It works great when I use expect interactively like this:
root@vagrantup:/home/vagrant> expect -i
expect1.1> spawn screen -x
spawn screen -x
3195
expect1.2> send "ls\n"
expect1.3> exit
But the same commands used in a file:
spawn screen -x
send "ls\n"
exit
Only works sometimes, eg. 1/10 time every time I execute the file. It’s really weird.
I execute the file with this command:
expect -f Expectfile
I have also tested these:
expect -b Expectfile
expect Expectfile
But I get the same error.
It doesn’t say anything. The other screen (since I’m using “screen” command) only responds sometime. Anyone knows why?
I hope you’re using
lsto stand in for something else, because if you just want a local listing of files, you’re far better off using theglobcommand. Of course, you might actually be doing something like that, what with the use ofscreen -xtoo, but it smacks to me of being a little over-complex right now.Possible failures (though I’m shooting in the dark here due to lack of evidence) could be an interaction between the various things using virtual terminals (both expect and screen do that, and there’s just not that many virtual terminals available system-wide) or some kind of timing problem due to not enough time for a connection to a session to be reestablished. (Failing 9 times out of 10 though? That’s a lot.) If it is the timing problem, inserting an
after 500will help. If it is the count of terminals, you’ve got problems; maybe it would be possible to spot this with a tool likelsofbut there’s a lot of moving parts and I don’t know what’s failing.