reading stdin in tcl/tk

Need help with C, C++, perl, python, etc?

reading stdin in tcl/tk

Postby utrrrongeeb » 2006-08-30 09:31

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
utrrrongeeb
 
Posts: 255
Joined: 2006-05-14 09:48
Location: Eastern Canada

Postby drl » 2006-09-21 19:38

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
drl
 
Posts: 434
Joined: 2006-09-20 02:27
Location: Saint Paul, Minnesota, USA

Postby utrrrongeeb » 2006-09-22 09:50

Thanks for the info, but I fixed the problem a different way with Bash.
utrrrongeeb formerly lecaro
Art #429775 on 'Etch' 4.0r0
User avatar
utrrrongeeb
 
Posts: 255
Joined: 2006-05-14 09:48
Location: Eastern Canada


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

fashionable