The Perl version is also available as a stand-alone executable file (exe file). Read more about packaging portable, 32-bit Windows executable files from Perl code here.
Read more about Perl on Windows here.
############################################################################ ## Prepare a perl script for being run from a network share ## ## or an UNC path. If you have the path \\server\share\perl\bin\perl.exe ## ## the specified path should be "-s \\server\share\perl". ## ## If it's on a mapped drive, it would be "-s X:\somedir\perl" ## ############################################################################ PS E:\temp> perl .\Perl2Cmd.pl Usage: Perl2Cmd.pl -f "file.pl" -s "\\server\share\perl" -o "outputfile.cmd" -f : .pl file to convert to .cmd -s : Server and share where Perl should be run from. Should be the Perl root directory as "\bin\perl.exe" will be appended. -o : Output file name. You will be asked to overwrite if it exists. Examples: Perl2Cmd.pl -f "get_files.pl" -s "\\server.domain.com\perl" -o "test.bat" Perl2Cmd.pl -f "do_stuff.pl" -s "\\dev-server\perl" -o "T:\do_stuff.cmd" You don't need to quote arguments unless they contain spaces. You can use either the .bat or the .cmd extension. The cmd extension allows for more advanced batch features, but does not run on NT4/Win98. None of these batch features are being used, so use whatever you prefer, with a note that .bat is more backwards-compatible. Author: Joakim Svendsen, Svendsen Tech, http://www.powershelladmin.comHere is an example of its use:
PS E:\temp> type .\perlcode.pl use warnings; use strict; print "This is the Perl code!\n"; PS E:\temp> perl .\Perl2Cmd.pl -f .\perlcode.pl -s C:\Perl -o perlcode.cmd Done! Output file for use with C:\Perl: perlcode.cmd PS E:\temp> .\perlcode.cmd This is the Perl code!
PS E:\> Get-Help .\Perl2Cmd.ps1 -detailed NAME E:\Perl2Cmd.ps1 SYNOPSIS Prepares a Perl script for being run from a Perl installation available from a UNC path, a local drive or a network drive, in a self-contained cmd/batch file, that also contains the Perl code. If you have the path \\server\share\perl\bin\perl.exe, the specified path to Perl2Cmd should be "-PerlShare \\server\share\perl". If it's on a mapped drive, it would be "-PerlShare X:\somedir\perl" Author: Joakim Svendsen http://www.powershelladmin.com/wiki/Self-contained_batch_file_with_perl_code.php SYNTAX E:\Perl2Cmd.ps1 [-PerlShare]Here is an example of the Powershell version:[-PerlScript] [-OutputFile] [ ] DESCRIPTION
PARAMETERS -PerlSharePath to root Perl directory, containing a bin subdirectory with perl.exe and a full Perl environment such as from a regular Strawberry or ActiveState Perl installation. -PerlScript Path to the Perl script you want to turn into a self-contained batch file. -OutputFile The name of the output file. If it exists, you will be prompted to overwrite. This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer and OutVariable. For more information, type, "get-help about_commonparameters". REMARKS To see the examples, type: "get-help E:\Perl2Cmd.ps1 -examples". For more information, type: "get-help E:\Perl2Cmd.ps1 -detailed". For technical information, type: "get-help E:\Perl2Cmd.ps1 -full".
PS E:\temp> .\Perl2Cmd.ps1 -PerlShare '\\2008r2esxi\perl' -PerlScript 'perlcode.pl' -Output test.cmd ########################################################## ### Creating cmd file: test.cmd ### Using Perl from: \\2008r2esxi\perl\bin\perl.exe ### From: perlcode.pl ########################################################## Done! PS E:\temp> .\test.cmd This is the Perl code!
PS E:\temp> type test.cmd @rem = '-- Batch wrapper created with Svendsen Tech Perl2Cmd -- @echo off \\2008r2esxi\perl\bin\perl.exe %0 %1 %2 %3 %4 %5 %6 %7 %8 %9goto endofperl
@rem '; use warnings; use strict; print "This is the Perl code!\n"; __END__ :endofperl
I've been using it like this with the "__END__" section at the bottom followed by ":endofperl", but you could also exploit the special batch ":EOF" marker, so you can use "goto :EOF" instead of "goto endofperl", and omit the "__END__" part.
@rem = '-- Batch wrapper created with Svendsen Tech Perl2Cmd (PowerShell version) --@echo off
\\server\perl\bin\perl.exe %0 %1 %2 %3 %4 %5 %6 %7 %8 %9goto :EOF
@rem '; use warnings; use strict; print "This is Perl code!\n"; print "This is even more Perl code\n"; my $i = 42; print $i, "\n";
Output from this script on my computer:
PS E:\> .\temp.cmd This is Perl code! This is even more Perl code 42 PS E:\>
''Keywords: perl2bat, perl2cmd, perl to batch file, perl2batch''
Perl Windows All CategoriesMinimum cookies is the standard setting. This website uses Google Analytics and Google Ads, and these products may set cookies. By continuing to use this website, you accept this.