Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Perl/Tk System Function Error

by perl.j (Pilgrim)
on Nov 18, 2011 at 00:41 UTC ( #938716=perlquestion: print w/ replies, xml ) Need Help??
perl.j has asked for the wisdom of the Perl Monks concerning the following question:

I am making an "all-in-one calculator" (I guess). Here is my code (I know I do not have all subroutines defined, I'm still working on this as you can see):

use 5.12.4; use warnings; use Tk; ##### Create MainWindow ##### my $button_menu = new MainWindow; ############################# ##### MainWindow Buttons##### my $calculator_button = $button_menu->Button(-text=>"Calculator", -width=>10, -relief=> 'raised', -command=>\&open_calculator)->pack(); my $formulas_button = $button_menu->Button(-text=>"Formulas", -width=>10, -relief=> 'raised', -command=>\&open_formulas)->pack(); my $lcf_button = $button_menu->Button(-text=>"Find LCF", -width=>10, -relief=> 'raised', -command=>\&open_lcf)->pack(); my $gcf_button = $button_menu->Button(-text=>"Find GCF", -width=>10, -relief=> 'raised', -command=>\&open_gcf)->pack(); ############################# sub open_calculator{ system(qq{start "C:\\Windows\\system32\\calc.exe"}); } MainLoop;

Why does the system function not open the Windows calculator? Also, is there any source code I could use to make a basic calculator in Tk?

Thanks!

--perl.j

Comment on Perl/Tk System Function Error
Download Code
Re: Perl/Tk System Function Error
by keszler (Priest) on Nov 18, 2011 at 01:07 UTC

    On my XP system, removing the double-quotes makes it run calc. With the double-quotes I get a command window. Not sure why, but

    system(qq{start C:\\Windows\\system32\\calc.exe});
    is the way to go. The same behavior occurs at the command prompt: with quotes, cmd window; without, calc.

      It works! Thanks!
      --perl.j

      Because you, like many, have not read "help start" or "help cmd"

      I use Proc::Background

      removing the double-quotes makes it run [...] Not sure why

      Simple: The first argument of the start command, when put in double quotes, is taken as the requested window title. If you need to quote the command to be started, you also need to provide a dummy window title, i.e.:

      system('start "" "C:\\program files\\my application\\kaboom.exe" /foo +/bar');

      Also note that system() has a special case on Windows to run a program (with arguments) without waiting for it, and without having to mess with any shell or the braindead start program. This is documented in perlport:

      system(1,'C:\\program files\\my application\\kaboom.exe','/foo','/bar' +); # ^-- the 1 is the special case for Windows

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Perl/Tk System Function Error
by zentara (Archbishop) on Nov 18, 2011 at 12:32 UTC
    is there any source code I could use to make a basic calculator in Tk?

    See Tk Virtual Keyboard.

    Also running the system command from a Tk program, will totally block the Tk eventloop until the system call returns, but it may work in your special case, as the eventloop should resume after the calculator window is closed.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://938716]
Approved by keszler
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-08-28 00:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (253 votes), past polls