Strawberry Perl batch file errors

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
Just installed Strawberry Perl, and their batch files (perldoc.bat, etc.) are emitting syntax errors under TCC 12, whereas there are no errors under plain vanilla CMD.EXE . Sample error:

Code:
[0]> perldoc -f reverse
The syntax of the command is incorrect.
A subdirectory or file .exe already exists.
Error occurred while processing: .exe.
A subdirectory or file more already exists.
Error occurred while processing: more.
Before I poke around to resolve it on my own (which I can probably do, given enough time), I thought I'd ask if others have run into this issue before and found a workaround. Thanks.
 
Jun 7, 2008
96
3
#2
On Fri, Jul 22, 2011 at 12:49 PM, epement <> wrote:

> Just installed Strawberry Perl, and their batch files (perldoc.bat, etc.) are emitting syntax errors under TCC 12, whereas there are no errors under plain vanilla CMD.EXE . Sample error:
>
>
> Code:
> ---------
> [0]> perldoc -f reverse
> The syntax of the command is incorrect.
> A subdirectory or file .exe already exists.
> Error occurred while processing: .exe.
> A subdirectory or file more already exists.
> Error occurred while processing: more.
> ---------
> Before I poke around to resolve it on my own (which I can probably do, given enough time),
> I thought I'd ask if others have run into this issue before and found a workaround. Thanks.
I don't see that here using the current TCC/LE:


>perldoc -f reverse
reverse LIST
In list context, returns a list value consisting of the elements
of LIST in the opposite order. In scalar context, concatenates
the elements of LIST and returns a string value with all
characters in the opposite order.

print join(", ", reverse "world", "Hello"); # Hello, world

print scalar reverse "dlrow ,", "olleH"; # Hello, world

Used without arguments in scalar context, reverse() reverses $_.

$_ = "dlrow ,olleH";
print reverse; # No
output, list context
print scalar reverse; # Hello, world

Note that reversing an array to itself (as in "@a = reverse @a")
will preserve non-existent elements whenever possible, i.e., for
non magical arrays or tied arrays with "EXISTS" and "DELETE"
methods.

This operator is also handy for inverting a hash, although there
are some caveats. If a value is duplicated in the original hash,
only one of those can be represented as a key in the inverted
hash. Also, this has to unwind one hash and build a whole new
one, which may take some time on a large hash, such as from a
DBM file.

%by_name = reverse %by_address; # Invert the hash



Note that their batch files do some sanity checks:

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

______
Dennis
 
#3
I'd look at the batch files for special characters, e.g. parameter, command
combination, etc.

On Fri, Jul 22, 2011 at 10:16, DMcCunney <> wrote:


> On Fri, Jul 22, 2011 at 12:49 PM, epement <> wrote:
>
>
> ---Quote---
> > Just installed Strawberry Perl, and their batch files (perldoc.bat, etc.)
> are emitting syntax errors under TCC 12, whereas there are no errors under
> plain vanilla CMD.EXE . Sample error:
> >
> >
> > Code:
> > ---------
> > [0]> perldoc -f reverse
> > The syntax of the command is incorrect.
> > A subdirectory or file .exe already exists.
> > Error occurred while processing: .exe.
> > A subdirectory or file more already exists.
> > Error occurred while processing: more.
> > ---------
> > Before I poke around to resolve it on my own (which I can probably do,
> given enough time),
> > I thought I'd ask if others have run into this issue before and found a
> workaround. Thanks.
> ---End Quote---
> I don't see that here using the current TCC/LE:
>
>
>
> ---Quote---
> >perldoc -f reverse
> ---End Quote---
> reverse LIST
> In list context, returns a list value consisting of the elements
> of LIST in the opposite order. In scalar context, concatenates
> the elements of LIST and returns a string value with all
> characters in the opposite order.
>
> print join(", ", reverse "world", "Hello"); # Hello, world
>
> print scalar reverse "dlrow ,", "olleH"; # Hello, world
>
> Used without arguments in scalar context, reverse() reverses $_.
>
> $_ = "dlrow ,olleH";
> print reverse; # No
> output, list context
> print scalar reverse; # Hello, world
>
> Note that reversing an array to itself (as in "@a = reverse @a")
> will preserve non-existent elements whenever possible, i.e., for
> non magical arrays or tied arrays with "EXISTS" and "DELETE"
> methods.
>
> This operator is also handy for inverting a hash, although there
> are some caveats. If a value is duplicated in the original hash,
> only one of those can be represented as a key in the inverted
> hash. Also, this has to unwind one hash and build a whole new
> one, which may take some time on a large hash, such as from a
> DBM file.
>
> %by_name = reverse %by_address; # Invert the hash
>
>
>
> Note that their batch files do some sanity checks:
>
> 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
>
> ______
> Dennis
>
>
>
>
>


--
Jim Cook
2011 Monday: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
Next year they're Tuesday.
 
#4
On Fri, Jul 22, 2011 at 12:49 PM, epement <> wrote:

I don't see that here using the current TCC/LE:

Code:
reverse LIST
            In list context, returns a list value consisting of the elements
            of LIST in the opposite order. In scalar context, concatenates
            the elements of LIST and returns a string value with all
            characters in the opposite order.
. . .
. . .

perl -x -S %0 %*

. . .
Dan, I also received the output of the function, but it was the error message which bothered me.

It turns out the error message is a "false positive" (issuing an error when there actually is none), so I have a resolution that works for me:

Code:
perl -x -S %0 %* 2>NUL
Thanks for your help.

Eric P.
 
Jun 7, 2008
96
3
#5
On Fri, Jul 22, 2011 at 3:59 PM, epement <> wrote:

> ---Quote (Originally by DMcCunney)---
> On Fri, Jul 22, 2011 at 12:49 PM, epement <> wrote:
>
> I don't see that here using the current TCC/LE:
>
> Code:
> ---------
> reverse LIST
> * * * * * *In list context, returns a list value consisting of the elements
> * * * * * *of LIST in the opposite order. In scalar context, concatenates
> * * * * * *the elements of LIST and returns a string value with all
> * * * * * *characters in the opposite order.
> . . .
> ---------
> . . .
>
> perl -x -S %0 %*
>
> . . .
> ---End Quote---
> Dan, I also received the output of the function, but it was the error message which bothered me.
I'm Dennis, not Dan. :-)


> It turns out the error message is a "false positive" (issuing an error when there actually is none), so I have a resolution that works for me:
>
>
> Code:
> ---------
> perl -x -S %0 %* 2>NUL
> ---------
Good, but I'd like to know why you *get* the error in the first place.
Like I said, I don't see it here.


> Thanks for your help.
You're welcome.


> Eric P.
______
Dennis
 
#6
Just installed Strawberry Perl, and their batch files (perldoc.bat, etc.) are emitting syntax errors under TCC 12, whereas there are no errors under plain vanilla CMD.EXE.
I have also experienced this under both 4NT and TCC. The error messages were very strange and didn't seem to pertain to the .cmd files that were launched. The only way I was able to work around these problems was to call the cmd files this way:

cmd /c name-of-.cmd-file-here

At least it worked. This problem was going to be difficult to debug, as the .cmd files in question were actually Perl scripts "wrapped" in a .cmd file -- a Perl "thing" I have never understood at all (if only I could find some documentation that explains it in terms an ordinary mortal can understand). Using the batch debugger wouldn't likely tell me anything about what the "wrapped" Perl scripts were doing to confuse 4NT or TCC; my Perl IDE wouldn't know what to do about the batch-file-specific commands.

In any case...clumsy-looking though it was, it did work.
 
Jun 7, 2008
96
3
#7
On Sat, Jul 23, 2011 at 9:48 PM, mikea <> wrote:


> I have also experienced this under both 4NT and TCC. The error messages were very strange and didn't seem to pertain to the .cmd files that were launched. The only way I was able to work around these problems was to call the cmd files this way:
>
> cmd /c name-of-.cmd-file-here
>
> At least it worked. This problem was going to be difficult to debug, as the .cmd files in question were actually Perl scripts "wrapped" in a .cmd file -- a Perl "thing" I have never understood at all (if only I could find some documentation that explains it in terms an ordinary mortal can understand).
Perl originated in Unix. Unix shells support what's known as shebang syntax.

In Unix shells, # is a comment delimiter, and what follows # in a
shell script is assumed to be a comment, and node script code the
shell should interpret. The exception to this is shebang, first
introduced to Unix in 1980, though it took a while to end up generally
implemented.

If the first line of the script begins with #!, what follows is
assumed to be the interpreter for the content of the file.

So I might write

#! /usr/bin/perl

<Various perl code>
# end

and the shell would call the perl interpreter to actually run the code
in the script. This is far more convenient than "perl -E <perl
program>" for frequently used tasks.

Cmd.exe on Windows isn't the Unix Bourne/Korn/C/Bash shell, and
doesn't understand #!, so a different method must be used.

Essentially, the wrapper lets you treat a perl script as a program
that can be run by simply double clicking on it or typing its name in
a console window.

______
Dennis
 
Jun 7, 2008
96
3
#9
On Sat, Jul 23, 2011 at 11:07 PM, Charles Dye <> wrote:

> ---Quote (Originally by DMcCunney)---
> Perl originated in Unix. *Unix shells support what's known as shebang syntax.
> ---End Quote---
> If I'm not mistaken, at least one Windows shell supports it, too *;-)
Sure. Cygwin's port of bash. :-)


> Charles Dye
______
Dennis
 

rconn

Administrator
Staff member
May 14, 2008
10,100
85
#10
> Just installed Strawberry Perl, and their batch files (perldoc.bat, etc.)
> are emitting syntax errors under TCC 12, whereas there are no errors
> under plain vanilla CMD.EXE . Sample error:
Not reproducible here; I get the same (apparently correct) output with TCC
and CMD. (They do some hardcoded checks for cmd.exe, but TCC doesn't have
any trouble executing the batch file.)

The error messages you're seeing are *not* coming from TCC, so I recommend
you contact the Strawberry Perl developers to see what they mean.

Rex Conn
JP Software
 
#11
Essentially, the wrapper lets you treat a perl script as a program that can be run by simply double clicking on it or typing its name in a console window.
That's easy enough to do with a script alone (either by typing the script's name at the command prompt or by clicking the script's icon in an Explorer folder window) when .pl is associated with perl.exe. I do it all the time.

But, this kind of .pl-within-.cmd-file appears to be designed to run even on machines that have no Perl installation at all. Just how that's accomplished, I don't know.

At any rate the error messages I see surely have an explanation but they appear nonsensical at the time that they occur. There's something that 4NT/TCC gets confused about -- something that doesn't go wrong when cmd.exe is first invoked just before the .cmd files (wrapped around Perl code) are run. I'd love to post one of them here for others to inspect...but they're proprietary to the company where I work and alas, I can't post 'em.
 
Jun 7, 2008
96
3
#12
On Sun, Jul 24, 2011 at 1:56 AM, mikea <> wrote:

> ---Quote (Originally by DMcCunney)---
> Essentially, the wrapper lets you treat a perl script as a program that can be run by simply double clicking on it or typing its name in a console window.
> ---End Quote---
> That's easy enough to do with a script alone (either by typing the script's name at the command prompt or by clicking the script's icon in an Explorer folder window) when .pl is associated with perl.exe. I do it all the time.
Sure, *if* .pl files are associated with perl. They may not be.


> But, this kind of .pl-within-.cmd-file appears to be designed to run even on machines that have no Perl installation at all. Just how that's accomplished, I don't know.
It's isn't. Look at the wrapper code:

@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


If I change the echo statement to on in one of the bat files and run
ir, I see this:


C:\strawberry\perl\bin


>crc32 crc32.bat
if "%OS%" == "Windows_NT" goto WinNT
perl -x -S crc32 crc32.bat
3795dce4
if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl

It sees I'm on a flavor of NT (XP in this case), and runs perl,
passing it the script to process.

If I do it from tcc, as I did above, %COMSPEC% is set to it. I'm not
running CMD.EXE, so the script branches to the end.

The wrapper code just tests that you're running a shell where the
errorlevel checks for perl not in path or script failed will be valid.


> At any rate the error messages I see surely have an explanation but they appear nonsensical at the time that they occur. There's something that 4NT/TCC gets confused about -- something that doesn't go wrong when cmd.exe is first invoked just before the .cmd files (wrapped around Perl code) are run. I'd love to post one of them here for others to inspect...but they're proprietary to the company where I work and alas, I can't post 'em.
I'm with Rex: I can't reproduce the errors either (under TCC/LE 12
here.) Do you see the same errors with the sample perl batch files
distributed with Strawberry?
______
Dennis
 
#13
Good, but I'd like to know why you *get* the error in the first place.
Like I said, I don't see it here.
Dennis, sorry that I accidentally called you Dan. My mistake.

I am posting because what I thought was a "fix" was absolutely not correct. The trick of appending "2>NUL" to the end of the command line to redirect errors to NUL is a mistake. I had tried:
Code:
from: perl -x -S %0 %*
to:   perl -x -S %0 %* 2>NUL
What happened is that it creates 2 new directories named ".exe" and "more" in every folder from which I issued a perldoc -f {function-name} command.

The real trick is to read the batch file more carefully:
Code:
BEGIN { $^W = 1 if $ENV{'PERLDOCDEBUG'} }
So, when I did "set PERLDOCDEBUG=1", I received more information, and was able to get a more satisfactory resolution.

(1) Return "perldoc.bat" to its original condition.

(2) Create a file called "more.cmd" and put it on the path ahead of the MS Windows version, normally stored at "c:\Windows\system32\more.com". Any path that is ahead of c:\windows\system32 will work.

In my case, I pointed more.cmd to invoke MiniTrue (http://adoxa.110mb.com/minitrue/index.html), a free software file pager/editor with a little more muscle than the Windows port of "less" (http://adoxa.110mb.com/less/index.html), a file pager popular in the Unix community. I have used them both for years.

(3) I don't know if it's important, but I did set the PERL5SHELL variable to TCC, like so:
Code:
set PERL5SHELL=TCC.EXE /C /X
I don't see a lot of attention to using TCC with Perl ...
 
Jun 7, 2008
96
3
#14
On Mon, Jul 25, 2011 at 3:07 PM, epement <> wrote:

> ---Quote (Originally by DMcCunney)---
> Good, but I'd like to know why you *get* the error in the first place.
> *Like I said, I don't see it here.
> ---End Quote---
> Dennis, sorry that I accidentally called you Dan. My mistake.
Not a problem.


> I am posting because what I thought was a "fix" was absolutely not correct. The trick of appending "2>NUL" to the end of the command line to redirect errors to NUL is a mistake. I had tried:
>
> Code:
> ---------
> from: perl -x -S %0 %*
> to: * perl -x -S %0 %* 2>NUL
> ---------
> What happened is that it creates 2 new directories named ".exe" and "more" in every folder from which I issued a perldoc -f {function-name} command.
Doing 2>/dev/null is a trick I'd use under Unix, because file
descriptor 2 is mapped by default to STDERR. For TCC, I think you
need to do >&> instead of 2>.


> *(2) Create a file called "more.cmd" and put it on the path ahead of the MS Windows version, normally stored at "c:\Windows\system32\more.com". Any path that is ahead of c:\windows\system32 will work.
>
> In my case, I pointed more.cmd to invoke MiniTrue (http://adoxa.110mb.com/minitrue/index.html), a free software file pager/editor with a little more muscle than the Windows port of "less" (http://adoxa.110mb.com/less/index.html), a file pager popular in the Unix community. I have used them both for years.
Hmmm. I use less here. I'll have to try minitrue, as the additional
functions is offers might be handy.


> I don't see a lot of attention to using TCC with Perl ...
I suspect most folks don't do it.
______
Dennis
 
#15
Hmmm. I use less here. I'll have to try minitrue, as the additional functions is offers might be handy.
I've already downloaded it and am checking it out. The TC Forums are a goldmine of helpful utility links.
 
Jun 7, 2008
96
3
#16
On Mon, Jul 25, 2011 at 3:54 PM, JohnQSmith <> wrote:

> ---Quote (Originally by DMcCunney)---
> Hmmm. *I use less here. *I'll have to try minitrue, as the additional functions is offers might be handy.
> ---End Quote---
> I've already downloaded it and am checking it out. The TC Forums are a goldmine of helpful utility links.
I actually already had minitrue, as I use just about everything Jason
Hood maintains. I'm simply accustomed to using less in a console
window. It looks promising. The one thing I don't see offhand from
less is the ability to call whatever is defined in %EDITOR% to edit
the file currently being viewed in the pager.
______
Dennis