Purpose: to provide guidelines, tips, techniques, etc. on writing Tcl/Tk/etc. scripts that ''wrap'' around an existing command line oriented application. By ''wrap'', I mean that the resulting script provides some additional ease of use or functionality over the original program, and that the user typically has minimal knowledge that the original application even exists. Common examples are the creation of a [GUI] interface for a command-line application [http://www.tldp.org/HOWTO/Scripting-GUI-TclTk/], and [adding Tcl/Tk to a C application] (as well as the cases which fit '''both''' those description). ---- Many people take advantage of [Expect] and [Tk] in writing GUI applications which interact with a character oriented application. Expect is quite useful when you are wanting to interact with an application that is written to interact with users directly via the terminal. One neat example that the Expect book discusses is wrapping a command like [ftp], for instance, and then providing your own ''hooks'' for adding new commands - say to gzip or ungzip files on your machine, or to define ''macros'' to perform common sets of ftp actions, etc. While this is indeed way cool, [CL] counsels that, in the twenty-first century, use of [vfs] or [tcllib]'s ftp client library is a considerably more elegant, robust, portable, and generally maintainable alternative. [LV] offers, as an alternative view, that he would much prefer to use an existing ftp client and write a _small_ amount of add on code than to write an entire ftp client ;) ... [Tcl] and [Tk] work just fine for writing application that take additional arguments or use the GUI to gather values to then be supplied to the wrapped command via its command line. The logical place for most newcomers to start would be "How to Use [C] and Tcl Together" [http://www.cuj.com/articles/2002/0212/]; the inconvenience there is the larger one of reading back-issues of the '''C/C++ Users Journal'''. ---- [[Lots more pointers: [Fortran] pages, wrap references, RE series, ...]] ---- [EKB] Some tips for [exec] to wrap a command-line program (a Windows example, but should be pretty straightforward to adapt it...): '''If you want to return control immediately to the calling program, use '&'''' tk_messageBox -message "Before loading" exec Notepad.exe tk_messageBox -message "After loading" will pop up "After loading" only after you close Notepad, while tk_messageBox -message "Before loading" exec Notepad.exe & tk_messageBox -message "After loading" will pop up "After loading" immediately after opening Notepad. '''Always wrap in a [catch] command - this will capture anything sent to stderr by the program''' if [catch {exec MyProg.exe my command line} errors] { # Clean up here... } '''Make sure you're in the proper directory for running the program, or provide a full path''' set currdir [pwd] cd "C:/some dir/to run/program/in" if [catch {exec MyProg.exe my command line} errors] { # Clean up here... } cd $currdir ---- [Category Discussion]