QNX4 Expect; eof problems; anyone fixed it?

Hi Folks,

I’m trying to use “expect” from the /usr/free dejagnu archive, and have run
into a little bit of a problem with the eof handling. I’m wondering if anyone
has fixed it?

Basically, I’m trying to spawn something like “sin” and parse the lines coming
back into an array:

#! /usr/local/bin/expect –

Capture the global names from the sin command

proc sin_gnames {gnames} {
upvar $gnames g

set i 0
spawn sin fo in

set timeout 1
expect {
eof {
wait
return 1
} -re “([^\r]*)[\r\n]+” {
set g([expr $i]) $expect_out(buffer)
incr i
exp_continue
} timeout {
wait
return 99
}
}
}

What happens is it returns “99” indicating timeout, rather than “1”
to indicate EOF. I’ve tried a few things like spawning a shell to
then spawn the “sin fo in”, or writing the output to a file and then
using “cat filename” on it – same results.

Any suggestions for the fix to expect? My “last resort” will be to
use a shell and interact with it with a unique prompt to detect EOF,
but that’s rather ugly :slight_smile:

Thanks in advance!
-RK

[posted to qdn.public.qnx4 as well]

Robert Krten, PARSE Software Devices; email my initials at parse dot com
Consulting, Systems Architecture / Design, Drivers, Training, QNX 4 & Neutrino
Check out our new QNX 4 and Neutrino (QRTP) books at http://www.parse.com/
Wanted PDP-8/9/10/11/12 Systems/documentation/spare parts! Will trade books!

Previously, Robert Krten wrote in comp.os.qnx:

Basically, I’m trying to spawn something like “sin” and parse the lines coming
back into an array:

I’d use awk for this instead of expect. Since you are parsing the
output of a spawn()'d command, the timeout detection capability of
expect isn’t factoring in to what you are doing.

I’m not an expert on regular expressions either so I’m not really sure what
you are trying to pull from the sin output. Here’s some awk:

!/bin/awk -f
{
print $1;
}

Usage would be (assuming the script was stored as file.awk and chmod 755):

sin | ./file.awk

Alternately you can invoke it this way:

sin | awk “{ print $1; }”

If you want awk to spawn sin, and then parse the out put, it’s only slightly
more complex…

!/bin/awk -f
BEGIN {
while( (“sin” | getline) > 0 ) {
print $1;
}
close( “sin” );
exit;
}

This will dump a list of the process names in QNX6. If you want the same thing in QNX4, then
change the $1 to a $3.

Cheers,
Camz.


Martin Zimmerman camz@passageway.com
Camz Software Enterprises www.passageway.com/camz/qnx/
QNX Programming & Consulting

Martin Zimmerman wrote:

Previously, Robert Krten wrote in comp.os.qnx:
Basically, I’m trying to spawn something like “sin” and parse the lines coming
back into an array:

I’d use awk for this instead of expect. Since you are parsing the
output of a spawn()'d command, the timeout detection capability of
expect isn’t factoring in to what you are doing.

I’m not an expert on regular expressions either so I’m not really sure what
you are trying to pull from the sin output. Here’s some awk:

!/bin/awk -f
{
print $1;
}

Usage would be (assuming the script was stored as file.awk and chmod 755):

sin | ./file.awk

Alternately you can invoke it this way:

sin | awk “{ print $1; }”

If you want awk to spawn sin, and then parse the out put, it’s only slightly
more complex…

!/bin/awk -f
BEGIN {
while( (“sin” | getline) > 0 ) {
print $1;
}
close( “sin” );
exit;
}

This will dump a list of the process names in QNX6. If you want the same thing in QNX4, then
change the $1 to a $3.

in QNX4 you can also use the ‘format’ command of ‘sin’ to achieve this:

sin for n
or
sin for a (to also get the command line args of each process)

very handy :slight_smile:
pitty QNX6 ‘sin’ is obsoleted…

Cheers,
Camz.


Martin Zimmerman > camz@passageway.com
Camz Software Enterprises > www.passageway.com/camz/qnx/
QNX Programming & Consulting