start

[Refer to Microsoft documentation.]

MS-DOS shell built-in command called with a filename that invokes the executable associated with the filename's extension. Acts about like double-clicking on a file in File explorer. Usage example from Tcl:

 eval exec [auto_execok start] {""} [list [file nativename $filename]]

On Tcl 8.5 (or later):

  exec {*}[auto_execok start] "" [file nativename $filename]

which, if filename ends e.g. in .htm, calls up IE (if that's your default browser); Win Word for .doc, etc.

Nits: If the first parameter is quoted, "start" will take it for a window title. Add an empty string to avoid the problem (see below). COMMAND.COM, CMD.EXE and the console command-line tools misunderstand "/" in filenames. Use [file nativename] to cure that.

[Use in invoking browsers.]

To launch a Windows application (such as Tk) from a console application (such as Tcl) in such a way that it returns only after the subprocess has terminated, use

      start /w wish83 myapp.tcl

As with most Windows command-line tools, see "start /?" from a command prompt for built-in help.


schlenk One caveat usually found the hard way, is the simple fact, that Microsoft found it amusing to implement start differently on Win9x and on Win2k/XP. So read its documentation before you use it. Try to start something like this on W95 and W2k an see what happens:

 start {c:\program files\tcl\bin\wish84} myapp.tcl

Hint (this works on W2k):

 start "" {c:\program files\tcl\bin\wish84} myapp.tcl

MHo: Some (other or additional) aspects and facts of start:

  • You can start something specifying a file instead of the associated program, e.g.: start test1.tcl or start text1.doc; (hopefully) the right program is opened with the specified file as an argument automatically if that filetype is registered... (have a look at the cmds ftype and assoc for file type - program associations).
  • As noted, start /W(ait) is 1) a way to serialize things and 2) the only way to get back the errorlevel from win32-GUI programs (console mode programs always start synchronously even without using start).
  • start is an internal command on NT/W2k/XP etc., that means: it is built right in cmd.exe, the command shell interpreter. On Win 9.x it is a separate executable (start.exe).
  • And to make things not too simple, the parameters/switches accepted by start are different on 9x and nt-based platforms.

MJ - Because of the parsing exec performs with respect to, for instance, ampersands, the versions of start above will not work with, for instance, http://www.google.com/search?q=tcl&oe=utf-8 . With TWAPI it is possible to access the CreateProcess WIN32 API directly leading to the following version of start which will work even if $name includes spaces or other "strange" characters (& > etc)

 proc start {name} {
   package require twapi
   ::twapi::create_process {} -cmdline "cmd /c start \"\" \"$name\"" -showwindow hidden
 }

[Explain winutils alternative--something like "winutils::shell myfile.doc", and so on]


JJS 8 June 2007 - In a unix CDE environment I think you would do something like

 exec /usr/dt/bin/dtaction Open <file>