Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 28 |
Nodes: | 6 (0 / 6) |
Uptime: | 50:21:51 |
Calls: | 422 |
Files: | 1,024 |
Messages: | 90,508 |
Hi,
I've got some executables built with kbskit on Windows and Linux, and
I'm trying to get one of them to copy itself to another file, as part of initialising a new VFS for an end user application.
The VFS was created with vlerq by kbs.tcl.
When the exetuable VFS attempts to copy itself to the target image
(opts(1) == the target file name) -
if {[catch "file copy $extraarg $argv0 $opts(1)" output ropts]} {
ErrorExit 1 "init: failed to create target VFS \"$argv0\": $output"
}
I get the error:
failed to create target VFS "...": can't overwrite file "..." with
directory
- because of course the VFS is also mounted and my script is running
inside of that.
I tried using [open ...] and [puts ... [read ..]] but the VFS image
file can't be opened while it's mounted.
I was able to successfully use [exec cp......], but external tools
probably won't be available on the end user systems and certainly not
on MS Windows.
But if the VFS is mounted then it's already been opened by the VFS
library itself. Perhaps there is a way of duplicating the file handle or accessing the naked VFS image file without invoking the VFS library?
Kind regards,
Scott
Perhaps you can exec [info nameofexecutable] itself to do the copy
in a cross-platform manner? Either (obviously untested)
set fd [open |[info nameofexecutable]...
puts $fd [list file copy [info nameofexecutable] target]
or
exec [info nameofexecutable] [file join [info nameofexecutable] yourcopyscript.tcl]
where youcopyscript is a Tcl script within your VFS that does
the copy.
Perhaps someone will suggest a simple way ...
/Ashok
On 4/21/2025 7:12 AM, Scott Pitcher wrote:
Hi,
I've got some executables built with kbskit on Windows and Linux,
and I'm trying to get one of them to copy itself to another file,
as part of initialising a new VFS for an end user application.
The VFS was created with vlerq by kbs.tcl.
When the exetuable VFS attempts to copy itself to the target image
(opts(1) == the target file name) -
if {[catch "file copy $extraarg $argv0 $opts(1)" output ropts]} {
ErrorExit 1 "init: failed to create target VFS \"$argv0\":
$output" }
I get the error:
failed to create target VFS "...": can't overwrite file "..."
with directory
- because of course the VFS is also mounted and my script is running
inside of that.
I tried using [open ...] and [puts ... [read ..]] but the VFS image
file can't be opened while it's mounted.
I was able to successfully use [exec cp......], but external tools
probably won't be available on the end user systems and certainly
not on MS Windows.
But if the VFS is mounted then it's already been opened by the VFS
library itself. Perhaps there is a way of duplicating the file
handle or accessing the naked VFS image file without invoking the
VFS library?
Kind regards,
Scott
On Mon, 21 Apr 2025 10:56:44 +0530
Ashok <apnmbx-public@yahoo.com> wrote:
I did try a simple test before I emailed, where argv0 and [info nameofexecutable] are the same thing -
set fdin [open $argv0 "rb"]
set fdout [open $opts(1) "wb"]
puts -nonewline $fdout [read $fdin]
- but this fails because $argv0 is already mounted automatically when
the executable is first run. Trying to open $argv0 is interpreted as attempting to open a directory for reading.
I'm looking at mk4tcl... source now and particularly mk4tcl.cpp. It
might be easier to expose either a binary dump of the file or handle
access.
Kind regards,
Scott
Perhaps you can exec [info nameofexecutable] itself to do the copy
in a cross-platform manner? Either (obviously untested)
set fd [open |[info nameofexecutable]...
puts $fd [list file copy [info nameofexecutable] target]
or
exec [info nameofexecutable] [file join [info nameofexecutable] yourcopyscript.tcl]
where youcopyscript is a Tcl script within your VFS that does
the copy.
Perhaps someone will suggest a simple way ...
/Ashok
On 4/21/2025 7:12 AM, Scott Pitcher wrote:
Hi,
I've got some executables built with kbskit on Windows and Linux,
and I'm trying to get one of them to copy itself to another file,
as part of initialising a new VFS for an end user application.
The VFS was created with vlerq by kbs.tcl.
When the exetuable VFS attempts to copy itself to the target image (opts(1) == the target file name) -
if {[catch "file copy $extraarg $argv0 $opts(1)" output
ropts]} { ErrorExit 1 "init: failed to create target VFS
\"$argv0\": $output" }
I get the error:
failed to create target VFS "...": can't overwrite file "..."
with directory
- because of course the VFS is also mounted and my script is
running inside of that.
I tried using [open ...] and [puts ... [read ..]] but the VFS
image file can't be opened while it's mounted.
I was able to successfully use [exec cp......], but external tools probably won't be available on the end user systems and certainly
not on MS Windows.
But if the VFS is mounted then it's already been opened by the VFS library itself. Perhaps there is a way of duplicating the file
handle or accessing the naked VFS image file without invoking the
VFS library?
Kind regards,
Scott