Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl/Tk Question

Status
Not open for further replies.

pbatt

Programmer
Joined
Sep 21, 2005
Messages
15
Location
US
Hi,

Has anyone ever launched an application from inside another application with the use of a button? Does that make sense?

I have 2 applications, say "app1.pl", and "app2.pl". I would like to launch app2.pl from a button in app1.pl. Both are Perl/Tk stand alone apps.

Here's what I thought would work:
$button = $lowerframe -> Button( -text=> "text", -background=>"lightgrey",-foreground=>"black",-command=>\./app2.pl, ) -> pack(-side=>"right",-anchor=>"se");

Get a lot of weird errors with that. Any suggestions?

Thanks!
 
You should be able to start app2 with "system('app2.pl')".
To do the job properly you should write a function that forks a child and then execs perl with app2.


Trojan.
 
When I try that, I get a Tk:Error, undefined subroutine &main...(command bound to event)

Any ideas?

What do you mean by forks a child then execs perl w/ app2?
 
Write a subroutine and call that with the "-command=>".
In the subroutine put the system call or a backticks call.


Trojan.
 
So maybe...

$button = $lowerframe -> Button( -text=> "text", -background=>"lightgrey",-foreground=>"black",-command=>\&getbutton, )

and...

sub getbutton{
system('app2.pl');
}
 
Hmmm. It didn't do anything at all?
 
Put a "print" or something into the subroutine to prove the code got in there.


Trojan.
 
Did this:

sub getbutton{
print "It got here\n";
system('app2.pl');
print "But not here\n";
}

Both statements printed?
It got here
But not here
 
Then the system command did not find your code.
Use:
system('perl /full/path/to/script/app2.pl');


Trojan.
 
That worked!

Again, thanks very much! I'm going to try and stay away from posting questions...could make me very lazy ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top