Perl execution from command line question - perl

I replaced ActivePerl with Strawberry Perl on my WinXP last week.
I found I must run my Perl script with the command of perl myperl.pl; otherwise I only need run myperl.pl before install Strawberry. How can I only run myperl.pl as before?
I checked my environment configuration as below.
C:\> Path
C:\Program Files\ActiveState Komodo Edit
5\;C:\Perl\site\bin;C:\Perl\bin;C:\Perl\bin\;C:\Program Files\CodeSynthesis
XSD 3.2\bin\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;
C:\Program Files\ATI Technologies\ATI Control Panel;C:\Program Files\Microsoft
SQL Server\90\Tools\binn\;C:\Program Files\Common Files\Thunder Network\KanKan
\Codecs;C:\strawberry\c\bin;C:\strawberry\perl\bin`
Strawberry Perl path already listed in the Path value after install successfully.
Anything I missed? Thank you for your suggestion.

Try from command prompt:
assoc .pl=PerlScript
ftype PerlScript=c:\strawberry\bin\perl.exe %1 %*
--
kmx

You need to associate .pl file extension with Strawberry Perl's executable (it's a Windows thing, not a Perl thing).
To do so, there are a couple of ways (you can google or ask on ServerFault for the best one or full list), but the one I usually use on XP is:
Open any folder Windows Explorer
Go into "Tools" menu, and click on "File Types" tab in the resulting dialog
Find "PL" extension in the list
If it's there, correct the associated executable to be Strawberry Perl's .exe by clicking on "PL" line and clicking "Change" button
If it's not in the list, click "New" button, type in PL extension in the form and click "OK". Then close the whole dialog, and re-open it again. The "PL" extension will now be in the list, so click on it and click "Change" button
In case I messed up, here's the official instructions from Microsoft:
http://support.microsoft.com/kb/307859
UPDATE
Please see kmx's answer - his method is all-command-line and as such seems much more preferable to me that GUI blundering... I confirmed that it works too (without parameters, at least)

You might need to put the .PL extension into the PATHEXT environment variable. This will make .pl files work with the PATH variable.
Type
set PATHEXT
to see if you're set up. If you're not, then go to My Computer->properties->Advanced and press the "Environment Variables" button on the bottom of the tab. There you can add .PL to the PATHEXT variable.
OR you could just set it in some batch file that you run to initiate cmd:
set PATHEXT=%PATHEXT%;.PL

For completeness here's 2 other methods that don't make a .pl script executable, but you could use them to make your perl script into an executable.
pl2bat which is suppose to create a wrapped version of your .pl into a .bat file which would be executable on a windows system. I haven't tried this so YMMV.
pp, part of the PAR::Packer module which I have used before works pretty well at rolling your perl scripts into executables.

Related

Can we run a Perl script in a browser without web server?

Is it possible to run a perl script in Activeperl without web server in windows 7.If possible what are the steps to follow?
I have simple registration form using Post method in HTML file.I'm using this HTML file in my .pl file.I'm using CGI module. While running the .pl file from the command promt the HTML file is running browser, after clicking submit button the perl script is displaying.
When you install ActivePerl, it creates a file association for .pl files, so simply double-clicking a .pl file in Explorer ("My Computer", "File Explorer", etc) will run it. This also makes it so you can run script.pl from the Windows Command Prompt.
When you install ActivePerl, it modifies your PATH to include the directory that contains perl.exe, making it so you can run perl script.pl from the Windows Command Prompt.
Finally, you can always run c:\...\bin\perl script.pl from the Windows Command Prompt.
Can you explain a bit more the exact use-case?
I think the first user in the comments gave you the best answer.
If Perl is not in your PATH environment you need to associate .pl extensions with Perl or run it via command-line ( if I remember correctly Active-Perl comes with a Perl command line tool )

Adding perl script to module distribution and making it accessible globally

I'm wondering if there is a tutorial or simple way to add perl scripts which I've written to be accessible to the user globally.
for eg. you apps like Carton, Cpanm, much like how npm has an npm install -g option.
I tried placing my scripts in the bin directory of my perl package but its not working.
The App::* area of cpan contains installable tools and utilities. Looking at a small one, like App::p I saw that its structure looked like it contained a Makefile.PL that used ExtUtils::MakeMaker to define how to build test and install the relatively small perl script.
However, if you're talking about just taking a script you wrote and making it something executable by you, the user, then it's basically the same way all scripting works (apologies if you weren't asking this):
One Unix, Linux and Mac OS X when using a shell like bash:
Any file can be made executable to the user by running chmod u+x filename
An executable file should start with a magic number, for plain text files containing scripts, the shebang is that number. So start your files with (as covered in man perlintro):
#!/usr/bin/perl
use strict;
use warnings;
When specifying an executable file from the command line you can type in the full path, possibly with conveniences from your shell. EG the file is at $HOME/myscripts/runme.pl you can type that at the prompt, the expanded /home/username/myscripts/runme.pl (/Users/username/myscripts/runme.pl on Mac OS X) or ~/myscripts/runme.pl at a bash prompt. Or if runme.pl is in your current working directory: ./runme.pl
If you just type runme.pl sh and bash and many shells will search your PATH variable in order and run the first runme.pl in any of the specified paths.
So if echo $PATH gives you something like: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin and you want the example in point 3 to work with just runme.pl you should
Either move the file into one of those directories (not recommended).
Or add export PATH=$PATH:$HOME/myscripts to the bottom of your ~/.bashrc or ~/.profile file or likewise for your preferred shell. Be sure to open a new login shell session, EG close that terminal window and open a new one.
On Windows, this is an exercise left to the reader. ☺

Cannot run any Perl scripts on Windows 8.1

I installed Active Perl 5.20
and also Strawberry Perl 5.20 after uninstalling Active Perl.
In both cases, when I open cmd and type 'perl' I get:
Unknown Unicode option letter ':'.
This error also prevents all scripts from running on my Windows 8.1 installation.
I uninstalled Perl and did a fresh install and it still doesn't work.
Are there dependencies that I need to install?
I googled the error but the results pertain to Linux installations where the script specified something wrong. But I get this error when I even try to use any perl command line or script. So my problem is not a faulty script.
That is the error message you get from using an invalid value for the -C command-line option. At a guess I'd say you have the PERL_UNICODE environment variable set to a string that contains a colon :.
Take a look at Command Switches in perldoc perlrun for more detail on this.
I too had this problem on windows 8.1 . The problem is that, once on installation, .pl files are not automatically recognized by Perl engine. So please select a .pl file and right click and say open with and set the default program to C\perl\bin\ inside it click perl.exe and recognize it. Once this is done your perl works flawlessly.

path of perl scripts [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am following the book 'Google Hacks'. It has many ready-made perl scripts, but it does not clearly say exactly where I need to save those perl scripts. I think I have to invoke these scripts from command line, but cannot figure out the location where these scripts should be stored. I am using Strawberry perl.
Also, it would be helpful I can run perl scripts from local environment setting with Internet connection, for example, to scrap Google search results. Thank you
note: I am using Apache webserver and windows 7 operating system
Are they on your server, or are they on your local machine? I'm assuming they're on your local system:
On Unix/Mac/Linux, the setup is fairly straight forward:
Make sure that the shebang points to your Perl executable. I make it #! /usr/bin/env perl which will find the perl command in my path.
Put the scripts in a directory in your $PATH variable.
On Windows, the setup is a bit more involved:
You need to setup your %PATH% environment variable to point to include your Perl scripts. You can do this by going into the System Control Panel (the easiest way is to right click on Computer on your desktop, and select Properties. Then go into Advanced Settings, and click on the Environment Varables... button on the bottom. Path is one of the System Variables.
You need to associate your *.pl suffix with your Perl executable. The problem is that Microsoft keeps changing this. However, the following works for Windows 7 and earlier:
Find a Perl script and view it in Windows Explorer. Right click on it, and open Properties. In Properties, there's an Opens with selection. Click on the Change button and select your Perl interpreter as your interpreter. Make sure the Always use the selected program to open this kind of file checkbox is checked.
Finally, you may want to set %PATHEXT% to include .pl as one of the executables. This way, you can type your Perl program without having to type the suffix all of the time. On Unix/Linux/Mac, you don't need suffixes because the shebang will point to the correct interpreter, but Windows must have a suffix associated with the executable. Now, instead of typing foo.pl on the command line, you can just type foo.
Once this is done, you can simply type in the name of your executable Perl script from any directory in the Command Prompt terminal and run your program.
The 1st thing you need to do, is to make sure that the .pl (or as some use, .plx) extension is associated in the windows registry as a perl program and that perl programs should be run by your perl.exe. At this point you should be able to run perl programs that don't require command line parameters just by double clicking them in Windows Explorer. I know that the installer for ActiveState Perl does this for you by default. I can't vouch for Strawberry.
To run them on the command line, you can just name their complete path ( C:\Mypath\Myprog.pl) or put them in a directory named in your PATH environment variable.
If you're trying to run them via Apache, you'll need to configure Apache with a CGI-BIN directory and put your CGI compatible perl programs in that directory. Again, Apache on Windows depends on the file extension associations in the registry, so make sure you've done that 1st step.

Eclipse: Add Command-Line Args to an OS X .app Directory

Is it possible to add custom command-line arguments to an Eclipse .app folder? In my particular case, I'm working with ZendStudio. I'm assuming the base Eclipse release would behave the same way.
I've found what looks like two different places that could work, but neither yield any results:
ZendStudio.app\Contents\info.plist
ZendStudio.app\Contents\MacOS\ZendStudio.ini
Am I looking in the right place, or is this even possible?
If you mean that you want to start Eclipse with some command line arguments, there is no file where you can add those to be used as default. But you can make a small script that will start Eclipse with the arguments you want, something like:
/Applications/Eclipse.app/Context/MacOS/eclipse some command line arguments
and then add executable permissions to your script, through Terminal window:
chmod 755 your_file
you can just type "chmod 755 " on the terminal and then drag and drop the script file on the terminal window, it will type the file's full path onto it, press ENTER and that's it. You can double-click your script file and it will start up Eclipse with the command line arguments you typed.