简体   繁体   English

如何自动执行Perl安装/脚本

[英]How can I automate a Perl installation / script

I'm brand new to Perl. 我是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. 不幸的是,由于人们必须下载并安装Strawberry Perl,从命令行手动安装一些CPAN模块,然后使用正确的参数运行脚本,因此难以设置。 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)? 我确定可以制作一个批处理文件来安装CPAN模块,但是如何设置环境变量(如果需要)呢? I don't suppose there is a way to automate the Strawberry Perl installation or have it 'come with' the necessary modules? 我不认为有一种方法可以自动完成Strawberry Perl安装或“附带”必要的模块?

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 如果您没有这样的东西,我建议您使用psexec http://technet.microsoft.com/en-gb/sysinternals/bb897553.aspx

You should be able to 'silent install' Strawberry Perl with the MSI installer. 您应该能够使用MSI安装程序“静默安装” Strawberry Perl。

http://msdn.microsoft.com/en-us/library/aa372024%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/aa372024%28v=vs.85%29.aspx

Then use psexec again, to do the CPAN installs. 然后再次使用psexec进行CPAN安装。

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. 如果您需要执行环境变量,则可以在您的perl脚本中执行此操作,或者您可能必须远程管理Windows注册表。

Create a BAT or CMD script that runs the Perl installer, followed by the CPAN install commands. 创建一个运行Perl安装程序的BAT或CMD脚本,然后是CPAN安装命令。 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. 诀窍可能是当BAT启动时,Perl安装区域( C:\\Perl\\bin或其他内容)将不在搜索路径上。 That will make it hard to run the CPAN commands. 这将使运行CPAN命令变得困难。 So, the BAT script should include a command to manually add the path to CPAN into the script's environment. 因此,BAT脚本应包含一个命令,以将CPAN的路径手动添加到脚本环境中。 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: 我使用ActiveState,而不是Strawberry Perl,但是我的安装程序如下所示:

@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! 最后一行将是cpan命令安装的ppm ,但希望您能理解!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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