From: Franc B. <br...@cb...> - 2002-03-11 23:01:53
|
Here is our take on the exec -- if you are interested to repeat our cross-platform experiment, cut the text below and place it under a mac, a unix, a linux. a ... directory as the following three files: @hypothenuse -- to be invoked as 'exec tclsh @hypothenuse' from a tclsh under any platform ( it also uses 'exec' to invoke hypothenuse below) hypothenuse -- a simple proc and its main (to be invoked by @hypothenuse) exec4mac.tcl -- Hemang Lavana's adaptation for Franc Brglez from http://mini.net/tcl/894.html Our requirement is to write tcltk once and run everywhere, including code that contains exec command. In this context, we would also be interested to hear from Jim about any follow-up his earlier work under http://www.usenix.org/publications/library/proceedings/tcl97/full_papers/ingham/ingham_html/ingham.html Thanks -- franc brglez -- >>>>>>>>> save as file '@hypothenuse' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< puts "\n... executing [file tail [info script]] under '$tcl_platform(platform)'\ \n... on [clock format [clock seconds]]" source exec4mac.tcl set aList {1 1 2 2 3 3 4} set bList {1 2 2 3 3 4 4} set cFile cValue foreach a $aList b $bList { exec tclsh hypothenuse $a $b $cFile source $cFile ;# the file $cFile contains the value of c puts "a=$a b=$b c=$c" } # % pwd # franc-OS9:CVSArchives:cbl:tcltkSW:ticklish:examples:exec4macTestDir: # % ls # @hypothenuse # exec4mac.tcl # hypothenuse # % source exec4mac.tcl # % # % exec tclsh @hypothenuse # # ... executing @hypothenuse under 'macintosh' # ... on Mon Mar 11 16:26:18 EST 2002 # a=1 b=1 c=1.41421356237 # a=1 b=2 c=2.2360679775 # a=2 b=2 c=2.82842712475 # a=2 b=3 c=3.60555127546 # a=3 b=3 c=4.24264068712 # a=3 b=4 c=5.0 # a=4 b=4 c=5.65685424949 # % # @vela: [132] cd exec4macTestDir # @vela: [133] tclsh # % ls # @hypothenuse exec4mac.tcl hypothenuse # % # % exec tclsh @hypothenuse # # ... executing @hypothenuse under 'unix' # ... on Mon Mar 11 16:24:08 EST 2002 # a=1 b=1 c=1.41421356237 # a=1 b=2 c=2.2360679775 # a=2 b=2 c=2.82842712475 # a=2 b=3 c=3.60555127546 # a=3 b=3 c=4.24264068712 # a=3 b=4 c=5.0 # a=4 b=4 c=5.65685424949 # % >>>>>>>>> end as file '@hypothenuse' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >>>>>>>>> save as file 'hypothenuse' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< proc hypothenuse {a b cFile} { set c [expr {sqrt( $a*$a + $b*$b )}] set fileId [open $cFile w] puts -nonewline $fileId "set c \"$c\"" close $fileId } eval hypothenuse $argv >>>>>>>>> end as file 'hypothenuse' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >>>>>>>>> save as file 'exec4mac.tcl' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< # exec4mac script, created from a mini.net posting by Hemang Lavana # for Franc Brglez, (October 2001). # # So far, this script works just fine under MacOS9.2 and Tcl/Tk 8.3.4 # (see the test example exec4macTest.tcl in this directory) # # FROM: http://mini.net/tcl/894.html # FILE: clone.tcl (original name) global tcl_platform if {$tcl_platform(platform) != "macintosh"} {return} global alreadySourced if {[info exists alreadySourced([info script])]} {return} set alreadySourced([info script]) 1 namespace eval ::exec4mac { variable vars namespace export exec } package require Tcl 8 ;# We use [namespace] now. # package require Tk proc ::exec4mac::slaveExit {slave {code 0}} { interp delete $slave #if {[llength [interp slaves]] == 0} {exit $code} } # Return list of commands in $slave in namespace $ns proc ::exec4mac::commandsIn {slave {ns {}}} { set cmds [$slave eval [list info commands ${ns}::*]] foreach child [$slave eval [list namespace children $ns]] { set cmds [concat $cmds [commandsIn $slave $child]] } return $cmds } proc ::exec4mac::slaveDisable {slave {code 0}} { # Prevent re-entrancy problems. Don't want deletion callbacks of # commands we redefine below (notably [.]) to recursively call us. $slave eval {proc exit args {}} # Convert all commands in $slave to no-ops. foreach cmd [commandsIn $slave] { if {[string match ::proc $cmd]} {continue} $slave eval [list proc $cmd args [list]] } $slave eval [list proc ::proc args [list]] # Delete $slave later. Make sure $slave is not deleted # within the current [update], if any. after idle [list after 1 [namespace code [list slaveExit $slave $code]]] return -code $code } proc ::exec4mac::exec {progName scriptName args} { global errorCode errorInfo # progName can only be 'tclsh' or 'wish' set pwd [pwd] #cd [file dirname $scriptName] set slave [interp create] $slave eval [list set argv0 $scriptName] $slave eval [list set argv $args] $slave eval {set argc [llength $argv]} #load {} Tk $slave #$slave alias exec ::exec4mac::exec $slave alias exit ::exec4mac::slaveDisable $slave # $slave eval { # bindtags . [linsert [bindtags .] end cloneMainWindow] # bind cloneMainWindow <Destroy> [list exit 0] # frame .clone # pack [button .clone.btn -text clone -command clone] -in .clone # pack .clone -side top # } set code [catch {$slave eval [list source $scriptName]} result] catch {$slave eval exit} cd $pwd return -code $code -errorcode $errorCode -errorinfo $errorInfo $result } # if {!$argc} { # return -code error "\nusage: exec appScript ?arg ...?" # } # wm withdraw . # clone [lindex $argv 0] [lrange $argv 1 end] namespace import ::exec4mac::exec >>>>>>>>> end as file 'exec4mac.tcl' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< At 3:16 PM +0100 3/11/02, Andreas Otto wrote: >Hi, > > there have to be a way to call additional executables from > a Tcl script > > I need the channel output back into a string > > I have an additional API for calling external SW -> > does Applescript helps ? > > does "open |..." works ? > > >well > > like you mention I'm working on a Mac port of "Compiler" > MacOS 9.1 well no 10 > > > I use Code Warrior (well the name fits exactly) > > 1) is a commandline interface available > > cammandline + some kind of exec would be perfect > > 2) is a cross compiler linux -> macOs9.1 ppc available > gcc does not support MacOs9.1 (this speak for them- > self) perhaps CodeWarrior ??? > > >mfg > > aotto > > >_______________________________________________ >Tcl-mac mailing list >Tc...@li... >https://lists.sourceforge.net/lists/listinfo/tcl-mac |