Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

running a script from Windows Desktop

by Anonymous Monk
on Mar 08, 2004 at 21:19 UTC ( [id://334934]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks , this might sounds like a stupid question but Is it possible to create an icon on your disktop which will call your perl script . I am writting a small script for a user who dosn't know what is command line mean . so I want him to click on the icon instead of the command line call. thanks .

20040310 Edit by castaway: Changed title from 'calling script from window'

Replies are listed 'Best First'.
Re: running a script from Windows Desktop
by TomDLux (Vicar) on Mar 08, 2004 at 21:23 UTC

    I'm guessing you mean on Windows. On my Win98 laptop :

    • right click on the desktop to pop up a menu, select NEW>>>SHORTCUT
    • In the text box type in the command line to be invoked,
      OR
      use the browse button to visually find the script / Perl binary.
    • Type the additional command line arguments.
    • Click NEXT
    • Provide a name for the link.
    • Click FINISH

    --
    TTTATCGGTCGTTATATAGATGTTTGCA

      I have Windows XP and I tried doing that. But it opens up in Notepad (the shortcut does) instead of executes in the command window as my script needs to. I have ActivePerl installed. How can I make a perl file execute in CMD?
        I guess you have to call the perl interpreter (with absolute path) and your script as parameter.

        So do I in my Icons under Win2k.

        HTH
Re: running a script from Windows Desktop
by arden (Curate) on Mar 08, 2004 at 21:23 UTC
    Assuming you mean for Win32, yes, you can create a shortcut by right-clicking on the desktop and selecting New->Shortcut and filling out the wizard. You can either call the script.pl directly with or without arguments or you can call perl with your script.pl as the first argument.

    Of course, if perl.exe is in their path and configured correctly (utilizing the .pl extension), they can just double-click on the script itself.

    - - arden.

Re: running a script from Windows Desktop
by Juerd (Abbot) on Mar 08, 2004 at 21:27 UTC

    Hi Monks , this might sounds like a stupid question but Is it possible to create an icon on your disktop which will call your perl script . I am writting a small script for a user who dosn't know what is command line mean . so I want him to click on the icon instead of the command line call. thanks .

    That depends on the kind of desktop that they use. Windows, KDE, Gnome and Mac OS all have different kinds of icon shortcut solutions.

    You could of course just associate .pl to be run by perl or create a real executable using PAR.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Re: running a script from Windows Desktop
by AcidHawk (Vicar) on Mar 09, 2004 at 06:03 UTC

    By creating a shortcut using "C:\perl\bin\perl.exe c:\somedir\yourscript.pl" you are effectively assuming that the user has perl on their desktop.

    If they do not know what a command line is why should they have perl installed..? (Unless of course you have installed it.)

    Another way would be to compile the perl source using something like Perl2exe and just copy the .exe and .dll to the users machine after which creating a shortcut would be as simple as drag and drop.

    -----
    Of all the things I've lost in my life, its my mind I miss the most.
Re: running a script from Windows Desktop
by wolfi (Scribe) on Mar 10, 2004 at 07:39 UTC
    ans: yes - i would dare say, you could run this via shortcut on any win32 system - (i can run it on winXp). What you need...
    1) create the shortcut. I simply right-click/send to desktop (create shortcut) or you can use the methods others have stated.
    2) ensure that the sys has perl (i use ActivePerl)
    3) associate it w/the perl-interpreter. Windows associates programs not by #! lines, but simply by theut extension. If you're rec'ving a notepad/text version, instead of it being executing, it's because the file-extension is associated w/that program (NOTEPAD).
    go into CONTROL PANEL -> FOLDER OPTIONS -> FILE TYPES and look for the extension .pl or .cgi (etc). Delete it.
    go back and double-click on it - you should rec'v the "OPEN WITH...?" prompt. From there browse thru your folders until you find your perl.exe ("perl command line interpreter") and select that.
    Next time it runs, it should execute the perl script via that.
    The ugly black box may quickly pop real brief - but whatever the results of the script (add file / delete file... etc) will be executed -> without your friend worrying about typing commands.
Re: running a script from Windows Desktop
by Corion (Patriarch) on Mar 10, 2004 at 07:46 UTC

    As an additional idea, ActiveState Perl comes with a nifty utility pl2bat, which wraps almost any Perl script in a .bat or .cmd file, which then can easily be sent somewhere as a shortcut.

    Personally, I don't use pl2bat much, I use the following template to start my Perl scripts in their "home directory", but this template only works on NT upwards:

    cd %~dp0 perl -w scriptname.pl "%1" "%2" "%3" "%4" "%5" "%6" "%7" "%8" "%9"

    That batch file must reside in the same directory as the .pl file. There is another utility that is even more general than my template, but I don't know the name. It is somewhere included in either ActiveState Perl or on the CPAN, and it is a batch file that starts the Perl script of the same name, so you'd copy it to somescript.cmd and it would try to start perl -w somescript.pl - that could be very useful as well.

Re: running a script from Windows Desktop
by fraktalisman (Hermit) on Mar 10, 2004 at 23:24 UTC
    and you can also use drag and drop in MS Windows. If you add %1 to the shortcut, the filename of a file dropped on the shortcut is handled to the script. To handle more parameters from other programs, %1 %2 %3 etc.
    So users won't even have to type.
    You say the person who will use it doesn't know what a command line is. This kind of people usually don't have perl installed, so you'd have to install for them. If you install anyway, it's also possible to install a web server and provide a "web" environment with the perl scripts. That would be something most computer users are quite familiar with, and using the script would be "just like surfing".
Re: running a script from Windows Desktop
by pbeckingham (Parson) on Mar 08, 2004 at 22:45 UTC
    I think these days the answer to this question is a ubiquitous 'Yes', regardless of your (unspecified) desktop environment. Furthermore, the mechanisms for this are all desktop-specific, and are not Perl-related.

    Now if you were asking about running scripts from the various command line interpreters out there, you would not be able to avoid typing in the file extension for Windows, as it doesn't completely obey the shebang.

Re: running a script from Windows Desktop
by ambrus (Abbot) on Mar 09, 2004 at 16:24 UTC

    If all the other suggestions fail, just create a batch file that starts perl with the script name as the argument.

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-20 03:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found