Jump to page sections
- Self-contained Batch File With Perl Code
- Download Perl2Cmd
- Documentation
- Perl Version Docs
- PowerShell Version Docs
- Example cmd file
Self-contained Batch File With Perl Code
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.Download Perl2Cmd
Documentation
Perl Version Docs
############################################################################
## 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.com
Here 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!
PowerShell Version Docs
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] [-PerlScript] [-OutputFile] []
DESCRIPTION
PARAMETERS
-PerlShare
Path 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".
Here is an example of the Powershell version:
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!
Example cmd file
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 WindowsBlog articles in alphabetical order
A
- A Look at the KLP AksjeNorden Index Mutual Fund
- A primitive hex version of the seq gnu utility, written in perl
- Accessing the Bing Search API v5 using PowerShell
- Accessing the Google Custom Search API using PowerShell
- Active directory password expiration notification
- Aksje-, fonds- og ETF-utbytterapportgenerator for Nordnet-transaksjonslogg
- Ascii art characters powershell script
- Automatically delete old IIS logs with PowerShell
C
- Calculate and enumerate subnets with PSipcalc
- Calculate the trend for financial products based on close rates
- Check for open TCP ports using PowerShell
- Check if an AD user exists with Get-ADUser
- Check when servers were last patched with Windows Update via COM or WSUS
- Compiling or packaging an executable from perl code on windows
- Convert between Windows and Unix epoch with Python and Perl
- Convert file encoding using linux and iconv
- Convert from most encodings to utf8 with powershell
- ConvertTo-Json for PowerShell version 2
- Create cryptographically secure and pseudorandom data with PowerShell
- Crypto is here - and it is not going away
- Crypto logo analysis ftw
D
G
- Get rid of Psychology in the Stock Markets
- Get Folder Size with PowerShell, Blazingly Fast
- Get Linux disk space report in PowerShell
- Get-Weather cmdlet for PowerShell, using the OpenWeatherMap API
- Get-wmiobject wrapper
- Getting computer information using powershell
- Getting computer models in a domain using Powershell
- Getting computer names from AD using Powershell
- Getting usernames from active directory with powershell
- Gnu seq on steroids with hex support and descending ranges
- Gullpriser hos Gullbanken mot spotprisen til gull
H
- Have PowerShell trigger an action when CPU or memory usage reaches certain values
- Historical view of the SnP 500 Index since 1927, when corona is rampant in mid-March 2020
- How Many Bitcoins (BTC) Are Lost
- How many people own 1 full BTC
- How to check perl module version
- How to list all AD computer object properties
- Hva det innebærer at særkravet for lån til sekundærbolig bortfaller
I
L
M
P
- Parse openssl certificate date output into .NET DateTime objects
- Parse PsLoggedOn.exe Output with PowerShell
- Parse schtasks.exe Output with PowerShell
- Perl on windows
- Port scan subnets with PSnmap for PowerShell
- PowerShell Relative Strength Index (RSI) Calculator
- PowerShell .NET regex to validate IPv6 address (RFC-compliant)
- PowerShell benchmarking module built around Measure-Command
- Powershell change the wmi timeout value
- PowerShell check if file exists
- Powershell check if folder exists
- PowerShell Cmdlet for Splitting an Array
- PowerShell Executables File System Locations
- PowerShell foreach loops and ForEach-Object
- PowerShell Get-MountPointData Cmdlet
- PowerShell Java Auto-Update Script
- Powershell multi-line comments
- Powershell prompt for password convert securestring to plain text
- Powershell psexec wrapper
- PowerShell regex to accurately match IPv4 address (0-255 only)
- Powershell regular expressions
- Powershell split operator
- Powershell vs perl at text processing
- PS2CMD - embed PowerShell code in a batch file
R
- Recursively Remove Empty Folders, using PowerShell
- Remote control mom via PowerShell and TeamViewer
- Remove empty elements from an array in PowerShell
- Remove first or last n characters from a string in PowerShell
- Rename unix utility - windows port
- Renaming files using PowerShell
- Running perl one-liners and scripts from powershell
S
- Sammenlign gullpriser og sølvpriser hos norske forhandlere av edelmetall
- Self-contained batch file with perl code
- Silver - The Underrated Investment
- Simple Morningstar Fund Report Script
- Sølv - den undervurderte investeringen
- Sort a list of computers by domain first and then name, using PowerShell
- Sort strings with numbers more humanely in PowerShell
- Sorting in ascending and descending order simultaneously in PowerShell
- Spar en slant med en optimalisert kredittkortportefølje
- Spre finansiell risiko på en skattesmart måte med flere Aksjesparekontoer
- SSH from PowerShell using the SSH.NET library
- SSH-Sessions Add-on with SCP SFTP Support
- Static Mutual Fund Portfolio the Last 2 Years Up 43 Percent
- STOXR - Currency Conversion Software - Open Exchange Rates API