exec() replaces the current process with a new one. When you call exec from the perl process that's running your Tk program you replace it with the exec'd process. The solution is to fork() and run exec() from the child process.
The only issue I'm not 100% certain about is the handling of the CHLD signal and child exit status, particularly when exec() fails. Hopefully someone with a better grasp of the issues can help clear that up.
Here's a short example:
#!/usr/bin/perl
use Tk;
sub go {
local $SIG{CHLD} = 'IGNORE'; # don't wait for child
# exit status. avoids
# zombies.
die "fork failed: $!" unless defined($pid = fork);
return if $pid;
exec("xterm");
warn "exec failed: $!";
CORE::exit(1);
}
$m = tkinit;
$m->Button(-text=>"Foo",-command=>sub{print"Foo\n"})->pack;
$m->Button(-text=>"Go",-command=>\&go)->pack;
MainLoop;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|