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?

3 Answers 3

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
Sign up to request clarification or add additional context in comments.

1 Comment

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.
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.

2 Comments

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.
Yeah, I had actually pulled ':' from awstats doc. Maybe cmd shell auto-fixes it?
0

Try calling perl explicitly:

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

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

3 Comments

nope, I've already registered the handler mappings to point .pl to the perl interpreter. Nice guess tho.
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.
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. =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.