tcl8.3.4 can't do an 'lindex $process 3' when process =
'000 S taps 30416 30415 0 76 0 - 559 wait4
00:24 pts/4 00:00:00 sh -c (cd
/usr/local/qt/doc/man && (echo ".ll 17.4i"; echo ".pl
1100i"; /bin/cat'
tcl8.3.4 can't do an 'lindex $process 3' when process =
'040 S taps 30417 30416 0 75 0 - 559 wait4
00:24 pts/4 00:00:00 sh -c (cd
/usr/local/qt/doc/man && (echo ".ll 17.4i"; echo ".pl
1100i"; /bin/cat'
(complains of semi colon following a double quote)
Logged In: YES
user_id=72656
Looks like the lindex isn't being done on a proper list.
Logged In: YES
user_id=99768
This is not a bug; [lindex] - and indeed all the list commands -
are documented to require well-formed lists as their arguments.
If you wish to separate a string into fields separated with
whitespace, do something like
[lindex [split $process { }] 3]
Note that Tcl 7.6 is the last release in which this code would
have worked - releases since then have attempted to parse
the entire list when processing [lindex].
Please feel free to ask on comp.lang.tcl for additional
information.
Logged In: YES
user_id=825002
original code was :
set target 2012
if { [catch {exec ps -efl} processes } {
puts "ERROR -- exec ps -efl failed -- $processes"
} else {
foreach process [split $processes "\n"] {
set pid [lindex $process 3]
if { $pid == $target } {
puts "found it!"
break
}
}
}
This works for all ps -efl output except the bug example.
I've worked around it by simply 'catch {lindex $process 3} pid'.
Sorry for the terse bug report -- I'm astonished you replied
so quickly!!!
Logged In: YES
user_id=99768
I still say we have a malformed list here.
A list element may be surrounded by double quotes, but
a list element surrounded by double quotes may not
have spurious characters after it. A simpler example is:
% lindex {"x"; "y"; "z"} 3
list element in quotes followed by ";" instead of space
The correct way to deal with this sort of data would be to
split the process line, replacing the
[lindex $process 3]
in your script with
[lindex [split $process] 3]
Logged In: YES
user_id=825002
Thank you!