Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Checking Expect/spawn error status using -open

97 views
Skip to first unread message

LisaY

unread,
Apr 4, 2008, 3:39:09 PM4/4/08
to
I'm running a non-interactive Tcl app that incorporates an Expect
loop, spawning and monitoring several concurrent processes (of another
application). Their spawn_ids are maintained in a list
(lstSpawnIDs). I'm using the basic syntax mentioned in Exploring
Expect pg. 292 (for reasons I'll skip for now), coupled with the if/
catch noted in the following section, pg. 296:

set strSpawn { spawn -open [open "| myapp args 2>logfile.txt" w
+] }
if [catch $strSpawn reason] {
<perform failure notification using $reason>
} else {
<successful spawn>
:
}
expect {
-i lstSpawnIDs
default {
<perform normal eof/timeout handling>
}
}

However I also acknowledge the footnote on pg. 296: " 'spawn -open'
returns a process id of 0 to indicate no process was spawned. There
is no process to kill."

The above code works most of the time, but produces "spawn_id expxxx
not open" under certain circumstances. This indicates that a spawn_id
was generated for myapp but some failure occured, closing myapp. I
have determined that the failure clause above is never invoked,
whether the spawn/open is successful or not, presumably because of the
footnote (process ID always = 0).

So my main question is: What's the best means of determining the
success/failure of the launch of myapp? I.e. I need to intercept the
"spawn_id expxxx not open" dialog and take appropriate action (retry,
abort myapp etc.).

I'd also be interested in a fuller understanding of the apparent
dichotomy of the footnote and the vertical bar indicating that a
process is actually spawned (which is indeed the case!).

Thanks in advance for any clarifications,
Lisa

Uwe Klein

unread,
Apr 5, 2008, 3:16:58 PM4/5/08
to
For robustness expect not only the patterns you wait for ( or a matchall
"default") but handle "timeout" and "eof"
if your expect reaches the "eof" special pattern your process has died.

>
> I'd also be interested in a fuller understanding of the apparent
> dichotomy of the footnote and the vertical bar indicating that a
> process is actually spawned (which is indeed the case!).

The [spawn] does not create a process.
But your [open "|........"] does.
the ~functional equivalent would be:

spawn myapp args

the -open option is imho more usefull for talking
to a serial line or similar.
If you have a process hanging on the fd you can
as well spawn this app directly.

uwe

0 new messages