For Programmers: Free Programming Magazines  


Home > Archive > Tcl > August 2007 > Re: figuring out a filename from it's handle...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: figuring out a filename from it's handle...
Bezoar

2007-08-31, 5:44 am

On Aug 30, 4:53 pm, daneyu...@gmail.com wrote:
> If I've lost track of a filename that a channel was opened for, is
> there a way to get the filename from just the channel name?
>
> In other words, after doing the following:
>
> set file_handle [open $filename r]
>
> can I then use $file_handle to determine $filename?
>
> -Daniel


just override your open call to creat an array of file descriptors
and their associated filenamss, or what not. Overload close to remove
from the global array

global fd2filename
array set { stdin stdin stdout stdout stderr stderr }

rename open Open
proc open { args } {
global fd2filename
set fname { lindex $args 0 ]
set fd [ eval Open $args ]
set fd2filename($fd) $filename
return $fd;
}
..... do same thing for close except you remove
the array index from the global array and when
you want to find out what the filename is you
merely

set fd [ open /tmp/log.file "r" 0660 ]
puts "filename for fd is $fd2filename($fd)"

I probably forgot something as I did not test this
out but it should work.

Carl

Glenn Jackman

2007-08-31, 9:24 am

At 2007-08-31 01:55AM, "Bezoar" wrote:
> global fd2filename
> array set { stdin stdin stdout stdout stderr stderr }

[...]
> I probably forgot something as I did not test this
> out but it should work.


Presumably you meant to say:
array set fd2filename { stdin stdin stdout stdout stderr stderr }


--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com