Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to read a file and set this information to a variable

Status
Not open for further replies.

cubicle4

Programmer
Jun 18, 2001
18
0
0
US
I need to be able to retrieve the contents of a file and set them to a variable.

Anyhow, this is what I have so far. I am able to return the channel fine but can't retrieve what is in the file. Here is the code snippet that I am using. Keep in mind that I have left out the fully qualified path for this example:

if [catch {open /files/23068.htm r} fileId] {
set stdErr "Cannot open file"
} else {
set fileOutput [read -nonewline $fileId]
close $fileId
}

TIA

Harold
 
I tried your snippet (on a text file) and it worked fine. I assume your target file exists? Is it, by any chance, binary (I wouldn't think so with the htm extension but I can't see why your script would fail otherwise)? Bob Rashkin
rrashkin@csc.com
 
Actually, just found out, that yes indeed it does work. Just so happens that the file I was trying to read had no data in it. Pretty funny, yet pretty stoopid. Should have confirmed the data first. Thanks - Harold
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top