novitiate has asked for the wisdom of the Perl Monks concerning the following question:

just trying to wrap a dump perl one-liner in a batch file
and it's not working. the batch writes a file's md5
cksum to stdout and takes two parms at the batch level:
c:\>md5.bat HEX file.txt
First parm is the type of output (hex,bin,base64)
Second parm is the file. Both are fed to the batch with
%1 and %2, respectively. Enuff about the .bat
Whenever i run this in the batch:
perl -MDigest::MD5 -e "print Digest::MD5->new->add(<>)->digest" %2
i get one cksum; but when i run it from the Win32 cmd console
i get a completely different chksum.

can anyone explain what's going on here. hunch is quirky behavior of STDIN, but i can't figure it out.

humbly,
novitiate

"...goodnight you princes of main(e)"  --The Cider House Rules

Replies are listed 'Best First'.
Re: win32 perl-in-batch
by belg4mit (Prior) on Apr 23, 2002 at 01:08 UTC
    I get the same for both.
    D:\>perl -MDigest::MD5 -e "print Digest::MD5->new->add(<>)->digest" md +5 japh.pl Can't open md5: No such file or directory at -e line 1. hi-bit-string D:\>foo.bat md5 japh.pl hi-bit-string
    Is the file you are using named something with spaces? If so you have to encase the name (and %2) in quotes to propagate the spaces. Also, there is no %1 in your example. Sample output and input files could have been useful as well.

    --
    perl -pew "s/\b;([mnst])/'$1/g"

Re: win32 perl-in-batch
by novitiate (Scribe) on Apr 24, 2002 at 02:51 UTC
    actually batch is called like this: c:\>md5.bat HEX file.txt
    Where %1 points to a label and %2 feeds the perl one-liner the file name. Here is the batch code:
    @echo off goto %1 goto END :BASE64 echo Digesting %2 d:\perl\bin\perl.exe -MDigest::MD5 -e "open(FH,shift);print Digest::MD +5->new->addfile(FH)->b64digest" %2 goto END :BIN d:\perl\bin\perl.exe -MDigest::MD5 -e "open(FH,shift);print Digest::MD +5->new->addfile(FH)->digest" %2 goto END :HEX d:\perl\bin\perl.exe -MDigest::MD5 -e "open(FH,shift);print Digest::MD +5->new->addfile(FH)->hexdigest" %2 goto END :END echo. echo Bye
    And the one-liner is executed:
    d:\perl\bin\perl.exe -MDigest::MD5 -e "open(FH,shift);print Digest::MD5->new->addfile(FH)->hexdigest" file.txt No space in the file name. It works every time, it's just that the hash is different for each method.
    Note:they are consistent in their disagreement.
    Here is the HEX output for the .bat method:

    b2dac3151aa297fe172ee847b9317c31

    Here is the output from the perl one liner run at the command line:

    7b3c4b4d258a62aa54821ad9e4cbfc05

    Thanks for the help!

    humbly,
    novitiate

    "...goodnight you princes of main(e)"  --The Cider House Rules