I'm brand new to Perl. We have a useful script in the office that people would like to use. Unfortunately it has been deemed hard to setup because one has to download and install Strawberry Perl, manually install a few CPAN modules from the command line, and then run the script with the right arguments. It's really not that bad and there is a readme to follow but is there an easier way to handle the installation? I'm sure I could make a batch file to install the CPAN modules, but what about setting up the environment variables (if needed)? I don't suppose there is a way to automate the Strawberry Perl installation or have it 'come with' the necessary modules?
How would you normally install software on client workstations? That's the method you should use now.
If you don't have anything like that, I would suggest using psexec http://technet.microsoft.com/en-gb/sysinternals/bb897553.aspx
You should be able to 'silent install' Strawberry Perl with the MSI installer.
http://msdn.microsoft.com/en-us/library/aa372024%28v=vs.85%29.aspx
Then use psexec again, to do the CPAN installs.
If you need to do environment variables, then you can either do that within your perl script, or you might have to mess with the Windows registry remotely.
Create a BAT or CMD script that runs the Perl installer, followed by the CPAN install commands. The trick is probably that when the BAT starts, the Perl install area (C:\Perl\bin or whatever) won't be on the search PATH. That will make it hard to run the CPAN commands. So, the BAT script should include a command to manually add the path to CPAN into the script's environment. You can even build up a list of modules, and run them in a loop. I use ActiveState, not Strawberry Perl, but my installer looks like:
#echo off
Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegQry% > "%TEMP%\checkOS.txt"
Find /i "x86" < "%TEMP%\CheckOS.txt"
If %ERRORLEVEL% == 0 (
echo This is 32-bit operating system...
\\Server\Shares\Installers\ActivePerl-5.16.3.1603-MSWin32-x86-296746.msi
) ELSE (
echo This is 64-bit operating system...
\\Server\Shares\Installers\ActivePerl-5.16.3.1603-MSWin32-x64-296746.msi
)
REM Even though the above stuff should have installed Perl locally and updated the PATH,
REM the new PATH won't be available in this BAT script since it was launched before the change.
REM Add both possible locations for local Perl to the PATH before running the PPM commands below.
PATH=C:\Perl64\bin;C:\Perl\bin;%PATH%
set MODULE_LIST=(Archive-Extract DBI DBD-ODBC Data-Validate Date-Manip Date-Simple File-Copy-Recursive List-MoreUtils Mail-Sender Mail-Sendmail Params-Validate SOAP-Lite Spreadsheet-WriteExcel Text-CSV Tie-IxHash)
for %%i in %MODULE_LIST% do cmd/c ppm install %%i
Your final line would be a cpan command install of ppm, but hopefully you get the idea!
Related
I need to write perl or shell scripts in windows environment for automation. Please suggest some freeware.
For perl I tried padre perl but post installation it requires connection with CPAN which my proxy doesn't allows.Hence its unable to identify modules once I run perl scripts.
Also for running Shell scripts I tried cygwin but its unable to identify loop statements while running shell scripts.
How should I go ahead?
Thanks in advance!
Why you don't use Activestate? I think is the best perl packaged system for Windows.
Here's the link for the free community edition:
http://www.activestate.com/activeperl/downloads
As for editors, you can also use Komod Edit: http://komodoide.com/komodo-edit/
I've recently installed the Perl Packer module to compile my perl scripts into exe packages. I'm running strawberry perl setup on a windows 32-bit machine. When I attempt to run the pp -o command, I get an error stating that Perl is not part of my path. It is, for some reason, looking for perl in F:/Programs/Strawberry Perl/site/bin/perl.exe, when the true path is F:/Programs/Strawberry Perl/bin/perl.exe. Perl itself runs fine from commandline. How can I get Perl Packer to find my perl.exe?
What about calling this way?
perl pp {your options goes here}
regards
I have to create an exe from a Perl script. I installed
ActivePerl-5.14.2.1402-MSWin32-x86-295342.msi
How do I install pp?
I know this is a relatively old question, but for the sake of others, here is a solution that worked for me using pp (Par Packager):
Install Strawberry Perl for windows (I installed strawberry-perl-5.16.3.1-64bit.msi)
I used 5.16.3.1 because I wanted to try out perl2exe as well, while I'm at it (perl2exe at the time supported only up to 5.16.3 version of perl)
Once installed, open Strawberry Perl Tools (e.g. through start menu -> All programs -> Strawberry Perl -> Tools), and invoke CPAN Client
In the client console that opens, type:
get pp
install pp
Once installation is complete, you can simply run:
c:\strawberry\perl\site\bin\pp.bat -o myScript.exe myScript.pl
Which will produce a myScript.exe which is a standalone executable (no external perl interpreter is needed)
Note: You can use the -d command line switch in order to reduce the size of the executable. This will not include perl interpreter code inside the executable, reducing the size of the executable, however you will need to provide perl5x.dll in the same directory as your executable, or include it on the PATH environment variable.
Until the issue with 1.010 is fixed, do the following:
Go to http://search.cpan.org/dist/PAR-Packer/
From the "Other releases" drop down list, select PAR-Packer-1.009 and download it
Decompress the archive, preserving directory structure
Run perl Makefile.PL
Install all the missing prerequisites by hand using ppm. E.g., ppm install Module::ScanDeps etc
Install MingW: ppm install MingW
dmake, then dmake test, then dmake install
Later, you can remove PAR::Packer from the site area using the ppm GUI and install the fixed version.
This is a Perl module called PAR::Packer, so it can be installed as any Perl module with CPAN. Unfortunately, you're using ActivePerl which isn't quite compatible with CPAN. Instead, you can see if use ActiveState's Perl Package Manager to install this module.
If the module isn't available via the Perl Package Manger, you can try installing with the CPAN command line utility. Open up a Console Window (Start->Accessories->Command Prompt) and type in cpan and press <ENTER>. Newer versions of ActiveState should automatically install the required compilers, etc. when you first start to use CPAN.
I prefer Strawberry Perl for Windows because it's more compatible with CPAN. However, ActivePerl has a lot of the Win32 modules already installed. Plus, it comes with the Perl Package Manager which is nice.
WARNING: ActiveState installs a lot of these Perl scripts not in C:\Perl\bin, but in C:\Perl\Site\bin which means you have to make sure that directory is in your path too.
As of v1.010, the software cannot be automatically packaged, see the report at Trouchelle's repo.
Install CPAN using PPM, then continue as per the Stack Overflow Perl FAQ: What's the easiest way to install a missing Perl module?
ppm install MinGW
cpanp i Win32::Exe PAR::Packer
In addition to the above answers,
You can use cpan to install the PAR::Packer.
From your windows command prompt use the command: cpan install PAR::Packer.
Note: I have Strawberry perl installed.
cpan installs the modules and the dependencies as well.
I have some problems to compile or run a Perl script in Windows. I have installed MinGW in my Windows to compile C code using the GCC package. Now, can I use MinGW to compile Perl script/code and how?
No. GCC does not include Perl. Try Strawberry Perl or ActivePerl for Windows which are Perl distributions for Windows.
See PAR::Packer's frontend pp, or "Cava Packager", or IndigoStar's Perl2Exe, or ActiveState's PerlApp
ActivePerl creates shortcuts for .pl files (if you check the box during installation). You can see the association by running the following from a prompt:
>assoc .pl
.pl=Perl
>ftype Perl
Perl="C:\Progs\perl5121-ap1201\bin\perl.exe" "%1" %*
(Use wahtever assoc returned as the argument for ftype.)
You can do it yourself with:
assoc .pl=Perl
ftype Perl=Perl="C:\Progs\perl5121-ap1201\bin\perl.exe" "%1" %*
(Use the correct path for your machine.)
Keep in mind that many scripts require command line inputs, and that the console closes down as soon as the script exits when you launch it from double-clicking. As such, it's often better to run your script from the prompt.
If you have the association setup as above, you can run a Perl script from the console simply by typing its name
>script.pl
Hello, World!
Or you can be explicit and specify that it requires Perl.
>perl script.pl
Hello, World!
That assumes that Perl is in the PATH. If not, you can specify the whole path to Perl.
>C:\Progs\perl5121-ap1201\bin\perl script.pl
Hello, World!
I just recently installed ActivePerl 5.12.2.1202 on my Windows XP in C:/Perl. I am new to Perl scripting.
I just want to run a Perl program which contains one print statement, which I saved in Notepad with the name ex.pl.
How can I run this Perl program?
Can I use an editor for typing a Perl script other than Notepad?
How do I use ActivePerl?
Run Perl program from command prompt
start->run>cmd (command prompt will appear), write perl full_path_of_your_script,
like
C:\> perl hello.pl #This assumes that perl is in your PATH environment variable.
There are many Perl Editors, you can
used for Perl scripts like DzSoft,
Perl Expess, Komodo Edit etc and also see http://www.perlmonks.org/?node_id=169668 and Perlfaq3- Windows Perl Editors for more detail.
Have a look at http://docs.activestate.com/activeperl/5.12/, for ActivePerl 5.12 documentation.
Perl programs (or any other program run by an interpreter) is run by passing the script as a command-line argument to the interpreter. For example, in this case:
perl.exe ex.pl
Padre the Perl IDE and Kephra are good editors for Perl.
As an alternative to ActivePerl, there is Strawberry Perl.
Perl programs are run using the Perl interpreter, perl.exe.
This is normally done from the command line:
C:\>C:\Perl\bin\perl ex.pl
If perl.exe is in your PATH environment variable that can be shortened to:
C:\>perl ex.pl
If you opted to have *.pl files associated with Perl during installation, you can also double-click on them from Windows Explorer.
If you have *.pl files associated with Perl and add .PL to your PATHEXT environment variable you can run them like any other executable:
C:\>ex
Perl programs are just text files. They can be edited with any text editor (Padre, Kokomo, vim, emacs, Notepad++, etc.). Use whichever one you like best.
ActivePerl is just a distribution of Perl. "Using" it usually means running perl.exe to execute your program. ActivePerl also includes the PPM (Perl Package Manager) utility to make it easier to install modules from CPAN, particularly if you don't have a C compiler available. Most experienced Perl developers prefer to use the cpan shell.
Just to add to the other answers, I use EPIC, the Perl eclipse plugin. I'm using Perl on a Windows 7 64 bit machine.
I still run scripts off the command line in windows using ActivePerl, but for development I like being able to dynamically step through the script line by line.
just to not paraphrase other answers and to be more helpful (even if the post is somehow old ) i recommend using the switch "-e" to run Perl scripts if they are composed of few statements e.g
Perl -e "print('hello')"
and of course this requires that the Perl executable is in the Path variable,if not and assuming Perl is under the folder c:\Perl , you can add it by taping :
set %PATH%=%PATH%;c:\Perl\bin
when it comes to the choice of text editor ,I'm still using Notepad++ for almost everything ,it come with some useful features like keywords highlighting and some auto-completion capabilities.