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?

FlavorScape
  • 13,301
  • 12
  • 75
  • 117

3 Answers3

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
brian d foy
  • 129,424
  • 31
  • 207
  • 592
  • 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 Apr 05 '12 at 20:14
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.

FlavorScape
  • 13,301
  • 12
  • 75
  • 117
  • 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 Apr 05 '12 at 17:44
  • Yeah, I had actually pulled ':' from awstats doc. Maybe cmd shell auto-fixes it? – FlavorScape Apr 05 '12 at 20:11
0

Try calling perl explicitly:

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

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

Barton Chittenden
  • 4,238
  • 2
  • 27
  • 46
  • nope, I've already registered the handler mappings to point .pl to the perl interpreter. Nice guess tho. – FlavorScape Apr 05 '12 at 00:43
  • 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 Apr 05 '12 at 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 Apr 05 '12 at 20:10