简体   繁体   中英

How can I automate a Perl installation / script

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM