Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2003-07-18
05:44 • Ticket [773280ffff] lindex bug status still Closed with 5 other changes artifact: a5f4b014aa user: sea001
05:24 • Closed ticket [773280ffff]. artifact: 2cd3dd580f user: kennykb
05:13 • Open ticket [773280ffff]. artifact: dfdda2ef75 user: sea001
05:06 • Closed ticket [773280ffff]. artifact: f7cfb5c780 user: kennykb
04:53 • Ticket [773280ffff]: 5 changes artifact: 3ef659c3ad user: hobbs
2003-07-17
21:29 • New ticket [773280ffff]. artifact: 98654f86a9 user: sea001

lindex bug

Closed / Accepted773280ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2003-07-17 21:29:14
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)
hobbsplain2003-07-18 04:53:14
Logged In: YES 
user_id=72656

Looks like the lindex isn't being done on a proper list.
kennykbplain2003-07-18 05:06:31
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.
sea001plain2003-07-18 05:13:27
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!!!
kennykbplain2003-07-18 05:24:36
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]
sea001plain2003-07-18 05:44:28
Logged In: YES 
user_id=825002

Thank you!
Log in (anonymous is fine) to add a comment.