Link to home
Start Free TrialLog in
Avatar of Tolgar
Tolgar

asked on

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

Hi,
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?

Thanks,
Avatar of FishMonger
FishMonger
Flag of United States of America image

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.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tolgar
Tolgar

ASKER

@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?
Avatar of Tolgar

ASKER

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?


http://munishbansal.wordpress.com/2008/12/21/passing-more-than-9-parameters-to-a-batch-file/

http://stackoverflow.com/questions/8328338/how-do-you-utilize-more-than-9-arguments-when-calling-a-label-in-a-cmd-batch-scr

http://hilmij.blogspot.com/2011/07/howto-passing-more-than-10-arguments-to.html


Thanks,
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial