NAME
blt_bgexec - Run Unix commands in the background

SYNOPSIS
blt_bgexec ?switches? varname arg ?arg ...?

blt_bgexec ?switches? arg ?arg ...?

DESCRIPTION

This command executes one or more Unix commands in the background as subprocesses, storing the output of the last subprocess in the variable varname after it has completed. This allows Unix commands to be run in the background, while still collecting their output, to notify the Tcl interpreter when they terminate.

This command, used in conjunction with tkwait, is particularly useful for handling Tk events while waiting for a running UNIX program to finish. blt_bgexec varname command args
tkwait variable varname

This allows expose events can be handled while waiting for one or more Unix commands to finish. The program may also continue, possibly animating a busy cursor or icon, while waiting for the variable varname to be set. After all the subprocesses have completed, blt_bgexec will set varname, triggering tkwait to return. Varname will contain the output of the last subprocess.

If the initial arguments to blt_bgexec start with - then they are treated as command-line switches and are not part of the variable name or pipeline specification. The following switches are currently supported:

-keepnewline
    Retains a trailing newline in the pipeline's output. Normally a trailing newline will be deleted.

-errorvar
    Name of a variable to be set with the contents of standard error after the last subprocess has completed.

-outputvar
    Name of a variable to be set with the contents of standard output after the last subprocess has completed. If varname is not specified, this switch must be set.

-updatevar
    Name of a variable which be appended with the standard output of the last subprocess. This variable is updated as data becomes available (i.e. read from the pipeline), unlike varname which is set after the last subprocess has completed.

--  Marks the end of switches. The argument following this one will be treated as the output variable name varName or the start of Unix command even if it starts with a -.

Command and args may be in any form accepted by the Tcl exec command. However, if output is redirected, the variable varname will be updated (at the next idle point) to the empty string. The command will still continue to completion.

You can also terminate to subprocesses by setting varname before the last command has completed. The remaining subprocesses will be killed.

BUGS
Care must be taken to prevent an application from preempting itself by further user-interactions (such as button clicks). The blt_busy command is very useful in these situations (see the blt_busy manual).

Unix commands (like compress) which close standard output prematurely confuse blt_bgexec. The workaround is to invoke the command through a Unix shell. blt_bgexec output /bin/sh -c "compress $file"

KEYWORDS
exec, background