|
2025-11-12
| ||
| 12:43 | • New ticket [aa9f3ef820] Inconsistent behavior of "file exists" command... artifact: 9f146e56ff user: anonymous | |
Inconsistent behavior of "file exists" command
Openaa9f3ef820b8c075c8fc663b6982704450e13912Created 1 year agoUpdated 1 year ago
Descriptionplain2025-11-12 12:43:04
Working with serial ports the "file exists" command has weird behavior, inconsistent with both "file type" and "::open" command (it's not the known pitfall of missing prefix \\.\ for serial ports on Windows platform):
---
a) The following returns 1 for EVERY serial port COM1 to COM9 (even if some of them do not exist):
for {set i 1} {$i < 10} {incr i} {
puts [file exists com$i]
}
Compared to this "file type" command works as expected and returns "characterSpecial" for serial ports available and raises errors for non-existing serial ports.
---
b) Adding \\.\ prefix for Windows changes behavior (although behavior of "file type" does not change):
for {set i 1} {$i < 10} {incr i} {
puts [file exists [string cat {\\.\com} $i]]
}
This returns zero for all serial ports COM1 to COM9 even if they are available. However the following succeeds (for serial ports available):
file type [string cat {\\.\com} 13]
---
c) For COM ports > 10 "file exists" always return 0 even if they are available, e.g.
puts [file exists {\\.\com13}]
always returns zero. However the following succeeds (given that serial port is available):
puts [file type {\\.\com13}]
# -> characterSpecial
set h [::open {\\.\com13} r]
close $h
---
The behavior seems inconsistent: Even if one defines that "file" commands work on disk files only why does "file exists" returns 1 for COM1 to COM9? And if one defines that "file" works on special devices like serial ports it should return 1 whenever "file type" returns "characterSpecial".
Commands "file readable" and "file writable" show similar behavior btw.
Platform is Windows 11 with Tcl 8.6.17 (other versions and platforms not tested yet).
Log in (anonymous is fine) to add a comment.