how to pass parameters to perl script from batch file

Go To StackoverFlow.com

2

So, I'm wondering how to pass parameters to a perl script from a .bat file in windows. I'm running active perl. If you're wondering why, I'm automating log indexing for awstats+iis.

I can do this fine just typing the command directly:

 awstats.pl -config:blahblah.com -update

I tried putting that in my batch file directly. I also tried using the standard batch file way:

 awstats.pl /config:blahblah.com /update

I even tried this, thinking the dash was parsed differently by perl:

 awstats.pl /-config:blahblah.com /-update

So I thought I'd try escaping the dash (for fun, of course):

  awstats.pl /%-config:blahblah.com /%-update

Then I tried the above combinations, attempting to escape the colon:

 awstats.pl /config%:blahblah.com /update

None of these produced the success screen I get when typing in the command. Yes, I had a pause so I could verify...

Any thoughts? Is there something obvious I'm missing about parameters?

2012-04-05 00:32
by FlavorScape


1

The problem was in batch file speak, the colon becomes an equals.

 awstats.pl -config=blahblah.com -update

That is odd though because the command line accepts a colon for params. Maybe it is magically ignored in batch files or something.

2012-04-05 00:42
by FlavorScape
Hmm... using '=' or blank between the switch and the following argument is the standard way that perl parses its arguments... I wonder why ':' was actually accepted when issued in the cmd shell. Run perldoc Getopt::Long for the gory details - Barton Chittenden 2012-04-05 17:44
Yeah, I had actually pulled ':' from awstats doc. Maybe cmd shell auto-fixes it - FlavorScape 2012-04-05 20:11


3

I know nothing about batch files, but many of the programs that come with Perl have batch file equivalents in Strawberry Perl. They all look like this, which is a clever use of perl's -x switch:

@rem = '--*-Perl-*--
@echo off
if "%OS%" == "Windows_NT" goto WinNT
perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofperl
:WinNT
perl -x -S %0 %*
if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
if %errorlevel% == 9009 echo You do not have Perl in your PATH.
if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
goto endofperl
@rem ';
...perl script goes here...
__END__
:endofperl
2012-04-05 07:42
by brian d foy
interesting, but I was looking for a more 'windowy' solution because we don't have a single perl developer here-- and it would be easier for future maintenance programmers to understand/update - FlavorScape 2012-04-05 20:14


0

Try calling perl explicitly:

perl awstats.pl -config:blahblah.com -update

Also make sure that perl is in your %PATH%.

2012-04-05 00:40
by Barton Chittenden
nope, I've already registered the handler mappings to point .pl to the perl interpreter. Nice guess tho - FlavorScape 2012-04-05 00:43
I don't think that's going to work in a batch file - Barton Chittenden 2012-04-05 00:56
If it's a handler/extension thing, give it a different extension and register that to whatever you like. Not that you should do that, but perl doesn't care what extension you use - brian d foy 2012-04-05 02:04
No, I got it working just fine now, see my answer. I'm updating 30 site log indices now at 2:30 every morning with a batch file. = - FlavorScape 2012-04-05 20:10
Ads