piper
piper

Reputation: 87

tclsh is stuck when executing external commands

When I type

exec vim

in tclsh it causes a jam, is there a way to catch this wrong usage behavior?

If I accidentally trigger such stuck tclsh behavior, how should I go back to tclsh?

tclsh8.5 % exec vim

At this time ctrl+c do not work. I don't want to use ctrl+z.

Upvotes: 0

Views: 198

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137577

The exec command in Tcl launches the other program as a subprocess and waits for it to terminate so that it can detect whether that command failed and report whatever output it produces as the command result. (That wait only blocks the current thread.) This is really good for some commands, but bad for others; vim is one of the not-very-good ones, especially as it doesn't really produce any output that exec can use as its result. On the other hand, provided you exit it then it will at least work. (You might also need to give <@stdin >@stdout arguments to exec to pass through standard input and output, things that an interactive editor might care about.)

Technically, you could launch vim as a background subprocess with exec vim & and the Tcl script would not wait (the result of the exec would be the process ID in that case).

Upvotes: 0

Related Questions