clacke
clacke

Reputation: 8026

Is there a way in tcl to replace the tcl process with the process of a command?

I would like to do the equivalent of exec in sh, or execve(2), just transfer control from tcl to a called command and never return, so that any signals sent to what used to be the tcl process go directly to the called command, stdout of the called command is the stdout of what used to be the tcl process, etc.

I have looked around in the manuals, but haven't found an obvious way to do this in tcl.

I'm not talking about tcl's exec, which keeps tcl running, creates a subprocess and captures its output, then resumes control flow in the tcl process.

Upvotes: 1

Views: 222

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137567

There's nothing built into Tcl itself at the moment, but the TclX extension includes a command, execl, which can do exactly what you want.

package require TclX

execl /bin/bash [list -c somescript.sh]

Note that doing an execl that fails may put the process in an inconsistent state, as some libraries use hooks to detect the underlying system call and close their resources. It depends on exactly what you're doing of course, but since the X11 library is a notable example of this, Tk applications are unsafe to continue the current process with if execl fails. (The fork/execl idiom — or Tcl's standard exec — doesn't have the problem, as the problem syscall always happens in a subprocess.)

Upvotes: 3

Related Questions