• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1018
  • Last Modified:

How to call a Perl file in .BAT file without number of input limitation?

I use a bat file to call a Perl file. The reason is to eliminate the need for the .pl extension. This is the code that I use in the .bat file:

@perl //path/to/a/directory/check %1 %2 %3 %4 %5 %6 %7 %8 %9

Open in new window

However, this code has a limitation of maximum 9 inputs. Since my Perl code may have more than 9 inputs, i would like to eliminate this limitation.

Can you please let me know how I can do it?

  • 3
  • 2
2 Solutions
Your reason for using a batch file wrapper is a little odd and unnecessary.

It is my understanding that batch files are limited to accepting a max of 9 parameters.  If your perl script needs more than that, then don't use a batch file as a wrapper.

If you want to execute a perl script without having to type its .pl extension, then simply add the .pl extension to the PATHEXT environment variable.
Just use "%*" instead of enumerating single variables; "%*" will contain the complete argument list:
@perl //path/to/a/directory/check %*

Open in new window

TolgarAuthor Commented:
@FishMonger: But I am writing this tool for others and due to business requirements, I cannot ask them to add the .pl extension to the PATHEXT environment variable.

@oBdA: I will try it. I hope it is that simple. Did you try it on a simple example?

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

TolgarAuthor Commented:
I found these pages on the web. They seem to be recommending the same method. And the last one is similar to oBdA's approach.

Can you please help me how to implement it to my example?




It looks like I was partially wrong.  I am correct in that using batch syntax, you can only access the %1 thru %9 args, however, I did not know that you could use the shift command to walk back through the arg names to access the next set of 9 args.

It should be noted that if perl was installed correctly, the .pl filetype ext will be configured with "%1" %* to allow for an unlimited number of args.  The solution that oBdA suggests duplicates that capability for the batch script without needing to use the shift command.

However, IMO, it is an odd if not an awkward and dumb approach to take simply because you don't want to type the .pl extension.

If this tool is going to be distributed to your customers, a better argument can be made to use perl2exe or similar app to package your tool up as a standalone .exe and not need to worry about writing batch script wrappers simply to eliminate the need to type the ext.
There is the most obvious solution that we missed.  Simply leave of the .pl extension when naming the script.  If you do that, you will need to call the perl interpreter directly and pass it the script, which is exactly what you're doing in the batch file.

D:\perl>type hello

use strict;
use warnings;
use Data::Dumper;

print "Hello World\n";

print Dumper \@ARGV;

Open in new window

See, no batch file and no .pl extension.
D:\perl>perl hello bill cathy joe sue mary ed jose scott sally dave john rich

Hello World
$VAR1 = [

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now