Version 6 of exec path problems

Updated 2008-01-28 16:14:00 by evilson

{

An exec Gotcha

Tcl looks for the command to be exec'd in a sequence of directories (PATH) that differs with the host platform. This sequence is documented in the exec man page: http://www.tcl.tk/man/tcl/TclCmd/exec.htm

A potential 'gotcha' occurs when the PATH used by the user's shell differs from that of Tcl. This is a 'gotcha' for all programs that need to execute other programs and isn't restricted to interpreters such as Perl/Python/PHP let alone Tcl.

When this happens calling the command from the shell or commandline (say Dos) works but execing it from Tcl either fails completely or calls a different program with the same name.

E.g. With ImageMagick installed on Windows

# this works
dos> convert a.tiff a.jpg

#but this results in an error
tclsh> exec convert a.tiff a.jpg
  Invalid Parameter - a.jpg
  Child process exited abnormally 

What's happening here is that Tcl is invoking C:\WINDOWS\system32\convert.exe while dos invokes the convert.exe installed in the ImageMagick directory.

The moral of the story is not to assume that because a command works from the commandline, it will also be exec'ed successfully by Tcl or any other interpreter or program.