Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between spawn and exec?

Tags:

I'm learning to write a TCL (expect) scripts and I notice that some examples show to use spawn, while others show the command exec. I tried googling, but can't find what is the difference?

Suppose I call 'exec' in a middle of a long expect script, what can I expect to happen?

like image 558
Milan Babuškov Avatar asked Feb 16 '09 19:02

Milan Babuškov


1 Answers

spawn is an expect command not a tcl command. exec is a tcl command.

spawn creates a process. The processes' input and output are connected to expect for use by the other expect commands: send, expect and interact.

exec creates a subprocess under tcl. In general the tcl is suspended until the subprocess completes. However, one can create the subprocess in the background (using & as the last argument) and if one hooks up the input and output correctly, tcl can interact with the subprocess. This is very clumsy and is exactly the sort of interaction that expect was designed to handle smoothly.

like image 101
Andrew Stein Avatar answered Nov 02 '22 19:11

Andrew Stein