InterGuru has asked for the wisdom of the Perl Monks concerning the following question:

I want to have a button on a Perl Tk window link to a web page under Win32.

I first create the button.

$dialog5 = $mainWin->Dialog( -title   =>  "About ActEudo", 
-buttons => [ "OK", "Buy" ], -command=>\&buyNow,);
Then I write the subroutine to link to the web page.

sub buyNow{
	my $but=shift; # Dialog sends button name as 1st parameter
	if($but eq “Buy”){
		$SIG{CHLD}='IGNORE';
		my $pid=fork(); # causes perl interpeter to collapse
		if ($pid){
		     my $cmd=`start www.interguru.com`;
		exit(0);
	         }
	   }
}

This same subroutine works under a plain ( non-Tk) perl script.
I am using activestate v5.4.8 under Win2000.

UPDATE
Feb. 8, 2005
I tried Win32::Spawn. It worked but the new IE window blocked my original program and I could not get any response from the main program until I closed the IE Window.

Then I did this and it worked, creating an independent process.
use Proc::Background
my $Iexplore = 'C:\Program Files\Internet Explorer\IEXPLORE.EXE';
sub instrPage{
     my $instrPage ="http://www.somethingxx.com";
	my $proc1 = Proc::Background->new($Iexplore, $instrPage );
	$proc1->alive;
}

  • Comment on Linking to Web from Tk Fork, Spawn and Proc Background

Replies are listed 'Best First'.
Re: Linking to Web from Tk perl
by jdporter (Paladin) on Feb 01, 2005 at 15:12 UTC
    Don't fork. It only takes a second or two to spawn the cmd.exe process (which runs the start), and that process is backgrounded, so control returns to your program pretty quickly.
      I originally did not fork. The program would hang up. Only when I ended the program with a cntrl-c, would the web site would appear. That is what led me to try a fork in the first place.
        Here's how I do it in Adso.pl, a Tk-based PerlMonks client:
        require Win32; { my $pid; Win32::Spawn( $path_to_firefox_exe, qq(-url "$url"), $pid ); }
        I may have been wrong about the cmd.exe thing.