Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

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

Try calling perl explicitly:

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top