Cover by Don Libes

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Setting Pty Modes From spawn

Pty modes can have a big effect on scripts. For example, if a script is written to look for echoing, it will misbehave if echoing is turned off. Suppose a script is driving a shell that prompts with a bare "%“. If the script sends the command "whoami\r“, the shell might return "whoami\r\ndon\r\n%“. In this case, the response could be matched with:

expect -re "\r\n(.*)\r\n% "

If the shell did not echo its input, the shell would return "don\r\n%“. But the expect command just shown fails to match this output.

For this reason, Expect forces “sane” pty modes by default. In fact, the sane flag is known to stty, the program which configures ttys and ptys. The particulars of sane differ from system to system; however, sanity typically implies characteristics as echoing, and recognition of erase and kill characters. Expect invokes stty to set the pty, so you can be assured that Expect’s version of sanity is just what your local stty thinks. If for some reason you believe stty’s understanding of sane is flawed and you are not in the position to change it (i.e., you do not have the source), you can redefine it when installing Expect on your system. This is covered in the installation procedure.

Unfortunately, one program’s sanity is another program’s gibberish. Some programs have special demands. As an example, it is possible to interact with a shell from inside of the Emacs editor (this has nothing to do with Expect so far). The shell session appears as a normal ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required