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

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,
0
Tolgar
Asked:
Tolgar
  • 3
  • 2
2 Solutions
 
FishMongerCommented:
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.
0
 
oBdACommented:
Just use "%*" instead of enumerating single variables; "%*" will contain the complete argument list:
@perl //path/to/a/directory/check %*

Open in new window

0
 
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?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

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?


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,
0
 
FishMongerCommented:
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.
0
 
FishMongerCommented:
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
#!/usr/bin/perl

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 = [
          'bill',
          'cathy',
          'joe',
          'sue',
          'mary',
          'ed',
          'jose',
          'scott',
          'sally',
          'dave',
          'john',
          'rich'
        ];
0

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