Re: struggling to figure out starkit -> file system stuff

"Uwe Koloska" <[email protected]> Sat, 14 Jul 2007 00:57:26 +0200
Newsgroups gmane.comp.lang.tcl.starkit
Message-ID <[email protected]>
Hello,

2007/7/13, lvirden <[email protected]>:
> package require Tk
> console show
> wm withdraw .
> puts "hello, world"
>
> puts "now, let's execute a bat file"
>
> set name [glob -nocomplain -dir $::starkit::topdir/lib/app-helloworld
> -- lwv*.bat]

this one gives you a list of files

> set rc [catch {file copy $name c:/temp/lwv.bat} output]

and here you feed this list into 'file copy' that only wants to get
one single filename.
The error message says it all:

> and the output I get is:
> now, let's execute a bat file
> file copy of {C:/Documents and Settings/lwv27/My Documents/MySoftware/
> Tcl/helloworld.vfs/lib/app-helloworld/lwv.bat} failed (error copying
> "{C:/Documents and Settings/lwv27/My Documents/MySoftware/Tcl/
> helloworld.vfs/lib/app-helloworld/lwv.bat}": no such file or
> directory)

The braces around the filename are part of the argument you hand over
to 'file copy'. The reason are the spaces in the path.  Try to create
two bat-files in the app dir and you get:
"{/path with/spaces/name1} /pathwithout/spaces/name2".

So because you look for all bat-files, you have to handle all
bat-files (or the special case of a list quoted single file):

set names [glob ...]
foreach fname $names {
  doWhatYouWant $fname
}


There is another shortcoming.  The bat-files are lying in the same
directory as the main script -- why didn't you use this:

  set names [glob -nocomplain -dir [file dirname [info script]] -- lwv*.bat]

and you should be ready if there are no bat-files.  So the copy
command has to go inside the test wether you get a filename at all:

So your program better looks like this

--- snip ---
package require Tk
console show
wm withdraw .

set tmpdir "c:/temp"
set appdir [file dirname [info script]]

puts "hello, world"

puts "now, let's execute the available bat-files"

set names [glob -nocomplain -dir $appdir -- lwv*.bat]
foreach fname $names {
    set newname [file join $tmpdir [file $tail $fname]]
    if { [catch {file copy $fname $newname} output] } {
	puts stderr "file copy of '$fname' to '$newname' failed ($output)"
	continue
    }
    puts "  exec $newname"
    set result [exec $newname]
    puts "  and the result is: $result\n"
} else {
    puts "no .bat file found in $appdir"
}
--- snip ---

Eventually the location for the temporary files should not be
hardcoded.  These wikipages give you some hints:
  http://wiki.tcl.tk/772  Creating Temporary Files
  http://wiki.tcl.tk/14944  execx - EXECuting transparently out of the
VFS of a starkit/starpack

Hope this helps
Uwe Koloska