Hi,filehandle
**file tempfile** create an temporary file and return a RW
→ good
If I want to use *this* file in an external tool like *less* etc I
need the filename → bad
question:
*how* I get the file-name from an open filehandle?
mfg
There's no way to get it later from the filehandle - bear in mind that
an open file could have multiple names (when there are hard links to it
in the filesystem) or no name at all (when the file has been deleted but still exists on disk because it is still open).
On 13/08/2022 13:28, Colin Macleod wrote:
There's no way to get it later from the filehandle - bear in mind that
an open file could have multiple names (when there are hard links to it
in the filesystem) or no name at all (when the file has been deleted but still exists on disk because it is still open).
This is exactly what [file tempfile] (when invoked without a nameVar argument) does on linux: It opens a file and then immediately deletes
it. Only because Tcl has an open handle to it, it can still be written
and read.
You can witness this as follows:
% set f [file tempfile]
file3
% file link /proc/[pid]/fd/[regsub {^file} $f {}]
/tmp/tcl_HKajFG (deleted)
So there is a platform-specific way to get the file from the file handle
on linux. But it will not help with providing access to the file to an external tool. For that you will need to pass the varName argument to
[file tempfile].
Schelte.
attribute $FH
FILE /my/path/to/File RDWR 0666 → easy to parse
Yes, it's a shame that Tcl doesn't support this.
c.f. Jim Tcl
. set f [open /etc/services]
::aio.handle5
. $f filename
/etc/services
On Saturday, August 13, 2022 at 10:05:43 PM UTC+10, Schelte wrote:
On 13/08/2022 13:28, Colin Macleod wrote:
There's no way to get it later from the filehandle - bear in mind thatThis is exactly what [file tempfile] (when invoked without a nameVar
an open file could have multiple names (when there are hard links to it
in the filesystem) or no name at all (when the file has been deleted but
still exists on disk because it is still open).
argument) does on linux: It opens a file and then immediately deletes
it. Only because Tcl has an open handle to it, it can still be written
and read.
You can witness this as follows:
% set f [file tempfile]
file3
% file link /proc/[pid]/fd/[regsub {^file} $f {}]
/tmp/tcl_HKajFG (deleted)
So there is a platform-specific way to get the file from the file handle
on linux. But it will not help with providing access to the file to an
external tool. For that you will need to pass the varName argument to
[file tempfile].
Schelte.
use cases:
1) cleanup temporary files after close socket
2) FH deep in "library"-code write better status/error message because *filename/type/openmode/permissions/* etc is known
3) from *socket* the FH has local and remote hostname and ip-address
4) MOST IMPORTANT no need to manage and track EXTRA variable(s) to store something line *filename* or *ip-address*
Hi,
I think this is useful because TCL is a controlled environment this mean every filehandle was crated by *open* *socket* etc…
→ there should be a general *attribute* function or *$FH attribute* method
example: FH from *open* return: FILE filename open access permission
attribute $FH
FILE /my/path/to/File RDWR 0666 → easy to parse
use cases:
1) cleanup temporary files after close socket
2) FH deep in "library"-code write better status/error message because *filename/type/openmode/permissions/* etc is known
3) from *socket* the FH has local and remote hostname and ip-address
4) MOST IMPORTANT no need to manage and track EXTRA variable(s) to store something line *filename* or *ip-address*
mfg
On 13.08.22 14:58, Steve Bennett wrote:
Yes, it's a shame that Tcl doesn't support this.
c.f. Jim Tcl
. set f [open /etc/services]
::aio.handle5
. $f filename
/etc/services
On Saturday, August 13, 2022 at 10:05:43 PM UTC+10, Schelte wrote:
On 13/08/2022 13:28, Colin Macleod wrote:
There's no way to get it later from the filehandle - bear in mind thatThis is exactly what [file tempfile] (when invoked without a nameVar
an open file could have multiple names (when there are hard links to it
in the filesystem) or no name at all (when the file has been deleted but
still exists on disk because it is still open).
argument) does on linux: It opens a file and then immediately deletes
it. Only because Tcl has an open handle to it, it can still be written
and read.
You can witness this as follows:
% set f [file tempfile]
file3
% file link /proc/[pid]/fd/[regsub {^file} $f {}]
/tmp/tcl_HKajFG (deleted)
So there is a platform-specific way to get the file from the file handle
on linux. But it will not help with providing access to the file to an
external tool. For that you will need to pass the varName argument to
[file tempfile].
Schelte.
I think this is useful because TCL is a controlled environment this mean every filehandle was crated by *open* *socket* etcノ
→ there should be a general *attribute* function or *$FH attribute* method
In article <td8tle$2t77e$1@dont-email.me>,
aotto1968 <aotto1968@t-online.de> wrote:
I think this is useful because TCL is a controlled environment this mean
every filehandle was crated by *open* *socket* etcノ
→ there should be a general *attribute* function or *$FH attribute* method
Every open and socket has to be written by a human who can save
the information in an array.
It's not a useful idea on unices because there is no good way to
derive a directory path from a file designator. The directory
path can be changed and even deleted after an open.
Hi,
**file tempfile** create an temporary file and return a RW filehandle
→ good
If I want to use *this* file in an external tool like *less* etc I
need the filename → bad
question:
*how* I get the file-name from an open filehandle?
mfg
I read the documentation and there is no info about how to get the "attribute" *seekable* out of the FH.
On 14.08.22 02:36, Siri Cruise wrote:
In article <td8tle$2t77e$1@dont-email.me>,
aotto1968 <aotto1968@t-online.de> wrote:
I think this is useful because TCL is a controlled environment this mean >>> every filehandle was crated by *open* *socket* etcノ
→ there should be a general *attribute* function or *$FH attribute*
method
Every open and socket has to be written by a human who can save
the information in an array.
It's not a useful idea on unices because there is no good way to
derive a directory path from a file designator. The directory
path can be changed and even deleted after an open.
I think the problem is *not* well understood
1. every FH in tcl was opened by TCL
2. TCL also knows *how* the FH was opened and has also the *attribute* data 3. the only problem is that the TCL "Tcl-Obj" technology requires that
every
object is *string-able* so the attribute data have to be a dict like struct
with *one* attribute is the original (old) FH.
4. other possible attributes are:
a) HOW was the FH created (OPEN, SOCKET, PIPE etc)
b) depend on a) additional attributes are (temporary, filename, mode, ipaddress, hostname, command etc)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 497 |
Nodes: | 16 (2 / 14) |
Uptime: | 16:43:28 |
Calls: | 9,785 |
Calls today: | 4 |
Files: | 13,748 |
Messages: | 6,187,612 |