Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

-Mouse

by tye (Cardinal)
on Apr 25, 2002 at 20:16 UTC ( #162087=snippet: print w/ replies, xml ) Need Help??

Description:

Convenient way to launch Perl scripts via the Win32 GUI.

Perfect for running Obfuscated Code with just a couple of mouse clicks.

# ouse.pm
# Instructions:
#    Install in your perl/lib or perl/site/lib directory
#    in a file named "ouse.pm".  Then enter the following
#    commands:
#        assoc .pl=Perl
#        ftype Perl=perl -Mouse "%1" %*
#    Then clicking on a *.pl file will cause the script to
#    run in a new window but the window will (usually)
#    not close when the script finishes.

END {
    print "Press ENTER to close: ";
    ''.<STDIN>
}

1;
Comment on -Mouse
Download Code
Re: -Mouse
by Mr. Muskrat (Abbot) on Apr 25, 2002 at 20:33 UTC
    I could do that... but I generally put scraps in test.pl and run them with test.bat that contains one line:
    perl test.pl
    That way, if I double click on a .pl file, it will be ran normally and I won't have to hit enter to end it. You see ActiveState Perl created a file association for me.

    Matthew Musgrove
    Who says that programmers can't work in the Marketing Department?
    Or is that who says that Marketing people can't program?

      I'm sorry tye. I was arrogant when I first joined Perl Monks.

      This is a great module that I use from time to time now.

      Update: Here is how to set it up on Windows 98. Save the following as a .reg file and double click it.

      REGEDIT4 [HKEY_CLASSES_ROOT\Perl\shell\Open\command] @="\"C:\\Perl\\bin\\perl.exe\" \"-Mouse\" \"%1\" %*"

      NOTE: Adjust the path to the Perl executable accordingly.

Re: -Mouse
by belg4mit (Prior) on Apr 25, 2002 at 20:40 UTC
    A bonus of this is, in case it's not obvious, that the window will stick around when something goes wrong.

    --
    perl -pew "s/\b;([mnst])/'$1/g"

Re: -Mouse
by munchie (Monk) on Apr 27, 2002 at 21:45 UTC
Re: -Mouse
by bbfu (Curate) on Jun 16, 2003 at 21:51 UTC

    A couple of comments.

    Firstly, I'd just like to point out that if the script has a syntax error, the window will still disappear. If this is a problem, it can be dealt with using the alternate method suggested by BrowserUk at Re: Small Problem with running Perl Scripts in Windows. His method has a side-effect of dropping to the command line when the script is done, instead of just prompting before closing the window.

    Secondly, my preference is to be able to press any key, not just enter, to close the window. The following slight modification is what I installed on my system:

    =head1 NAME ouse.pm =head1 SYNOPSIS perl -Mouse file.pl =head1 DESCRIPTION Install in your perl/lib or perl/site/lib directory in a file named "ouse.pm". Then enter the following commands: assoc .pl=Perl ftype Perl=perl -Mouse "%1" %* Then clicking on a *.pl file will cause the script to run in a new window but the window will (usually) not close when the script finishes. =head1 AUTHOR tye http://perlmonks.org/index.pl?node_id=162087 =cut END { eval " use Term::ReadKey; "; unless($@) { print "Press any key to close..."; ReadMode(3); ReadKey(); ReadMode(0); } else { print "Press ENTER to close: "; <STDIN>; } } 1;

    But definitely, ++tye. :)

    bbfu
    Black flowers blossom
    Fearless on my breath

Re: -Mouse
by jimbojones (Friar) on Apr 15, 2005 at 18:54 UTC
    I was having issues with the following:
    > foo.pl
    calling the wait condition
    > perl foo.pl
    doesn't wait.

    I modified ouse.pm to use Win32::Process::Info to see if the parent process is Windows explorer.

    Update: missing line from code
    =head1 NAME ouse.pm =head1 SYNOPSIS perl -Mouse file.pl =head1 DESCRIPTION Install in your perl/lib or perl/site/lib directory in a file named "ouse.pm". Then enter the following commands: assoc .pl=Perl ftype Perl=C:\Progra~1\perl\bin\perl -Mouse "%1" %* Then clicking on a *.pl file will cause the script to run in a new window but the window will (usually) not close when the script finishes. =head1 AUTHOR tye http://perlmonks.org/index.pl?node_id=162087 =cut use Win32::Process::Info; END { #-- find the parent process; my $pi = Win32::Process::Info->new(); my @info = $pi->GetProcInfo ( $$); my @pinfo = $pi->GetProcInfo ( @info[0]->{ParentProcessId} ); #-- see if the parent process is the windows explorer. if ( $pinfo[0]->{CommandLine} =~ /explorer/i ) { eval " use Term::ReadKey; "; unless($@) { print "Press any key to close..."; ReadMode(3); ReadKey(); ReadMode(0); } else { print "Press ENTER to close: "; <STDIN>; } } } 1;
Re: -Mouse
by runrig (Abbot) on Mar 03, 2006 at 01:23 UTC
    I changed it to not prompt when it runs Perl/Tk programs:
    if ( ! exists $INC{"Tk.pm"} ) { print "Press ENTER to close: "; ''.<STDIN> }

    Also, the ftype wouldn't work until I supplied the full path to perl.exe:

    ftype Perl=c:\perl\bin\perl.exe -Mouse "%1" %*

Back to Snippets Section

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2014-12-27 01:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls