Neatware Header
Home   Products   Solutions   Partners   Store   Company   

Expect Examples

This Expect example shows how to launch several Notepad programs, gets process id, waits for seconds, and then closes all processes. You can edit following code and execute Run expect item under the Build menu. It shows the potential to integrate your applications with Expect under MyrmecoX.

Use expect package. spawn, close, and wait.

package require Expect

set timeout variable to -1 so no timeout to execute the code. The default timeout value is 10. Usually this is the first statement! n is the number of spawned processes.

set timeout -1; set n 2

launch n Notepad programs by spawn command; store process id in sp array with index from 0 to n; and wait 10 secondes.

for {set id 0} {$id < $n} {incr id} {
  spawn -noecho notepad.exe; set sp($id) $spawn_id
}

after 10000

close all processes. The -i tag indicates that the next argument is a process id. Use wait to make sure the close be finished.

for {set id 0} {$id < $n} {incr id} { 
  close -i $sp($id); wait -i $sp($id)
}


Google
  Web Neatware.com