Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

reading stdin in tcl/tk

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
User avatar
utrrrongeeb
Posts: 254
Joined: 2006-05-14 09:48
Location: Eastern Canada

reading stdin in tcl/tk

#1 Post by utrrrongeeb »

I don't know tcl/tk, but I want to try using it for something. It needs to load about a kilobyte off stdin (from a pipe). Could someone explain how to do this?
utrrrongeeb formerly lecaro
Art #429775 on 'Etch' 4.0r0

User avatar
drl
Posts: 427
Joined: 2006-09-20 02:27
Location: Saint Paul, Minnesota, USA

#2 Post by drl »

Hi, lecaro.

I needed to shift my mental gears slightly for this because I've been doing a lot of perl lately. I had a few moments today, and I did some tcl scripting a few years ago at a networking company. I hasten to add that I didn't write as much tcl as I had written perl, and I could not have done this off the top of my head now.

You can find information like this in Brent Welch's Practical Programming in Tcl and Tk, 3rd, and other references as well. The driver script driver1 uses a here document to feed 4 lines into the tcl script t2 -- note the pipe symbol on the same line as the cat command ... cheers, drl

Code: Select all

#!/bin/sh

# @(#) driver1  Send some input to tcl script in file t2.
#
# A blank line is included; some tcls might need use of eof
# function.

cat <<EOF |
one
two

three
EOF
./t2

Code: Select all

#!/usr/bin/tclsh

# @(#) t2       Demonstrate tclsh read from stdin.

set channel {stdin}

while { [ gets $channel line ] >= 0 } {
        puts $line
}
And when driver1 is executed, the following is produced:

Code: Select all

% ./driver1
one
two

three
I think it's a good thing to try features, and, if you run into trouble, post what you have, and ask specific questions ... cheers, drl
["Sure, I can help you with that." -- USBank voice recognition system.
( Mn, 2.6.x, AMD-64 3000+, ASUS A8V Deluxe, 3 GB, SATA + IDE, NV34 )
Debian Wiki | Packages | Backports | Netinstall

User avatar
utrrrongeeb
Posts: 254
Joined: 2006-05-14 09:48
Location: Eastern Canada

#3 Post by utrrrongeeb »

Thanks for the info, but I fixed the problem a different way with Bash.
utrrrongeeb formerly lecaro
Art #429775 on 'Etch' 4.0r0

Post Reply