Reputation: 2019
How to really "open" the txt file (already know the file path), I mean, to pop out on the screen, by writing a tcl script? Thank you!
Upvotes: 1
Views: 2105
Reputation: 137667
Invoking the system “preferred” text editor is relatively easy, but not very portable. Assuming that $theFilename
contains the name of the file as Tcl understands it, and that it is not a file on one of Tcl's virtual filesystems:
exec open [file normalize $theFilename]
exec xdg-open [file normalize $theFilename]
Or, if you're in a terminal and like the classic method:
exec $::env(EDITOR) [file normalize $theFilename] <@stdin >@stdout 2>@stderr
(You probably ought to also check for the VISUAL
environment variable before the EDITOR
environment variable. Or just fire it into the GUI with xdg-open
…)
exec {*}[auto_execok start] "" [file nativename [file normalize $theFilename]]
Yes, that empty argument is necessary (especially when a directory or file has a space in it); start
has horrible syntax.
Upvotes: 2
Reputation: 40743
I assume by open, you meant open using an application/program. On Windows:
exec notepad.exe /path/to/file.txt
On Mac:
exec open /path/to/file.txt ;# Open using default application
or:
exec open -a TextEdit /path/to/file.txt ;# Open using a specific application
Upvotes: 0