[Distutils] small improvement of the script functionality under win32

Trent Mick trentm at ActiveState.com
Mon Apr 4 20:26:21 CEST 2005


[Phillip J. Eby wrote]
> At 08:14 AM 4/3/05 +0200, Vivian De Smedt wrote:
> >Could you confirm me that the %* isn't working on win95/win98 ?
> 
> test.bat:
> @echo off
> echo %*
> 
> Running 'test test' Outputs an '*', not any arguments.  So no, it doesn't 
> work.

Here is what the Perl world does with there perl2bat conversion:

    @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
    #line 15
        eval 'exec C:\Perl58\bin\perl.exe -S $0 ${1+"$@"}'
        if $running_under_some_shell;
    ...

Obviously we can't do the kind of script-as-a-batch-file wrapping that
Perl can get away with with its @array_variable_name syntax, but there
are some good ideas here:

- If one *is* using a WinNT-flavour Windows then the "%*" mechanism gets
  used, otherwise it gracefully falls back to the explicit "%1 %2 %3
  ..." for Win9x-flavours.
- If on WinNT *and* the COMSPEC is cmd.exe then the %ERRORLEVEL% 9009
  code is used to deal with "perl" (in our case "python") not having
  properly been found.

Cheers,
Trent
 
-- 
Trent Mick
TrentM at ActiveState.com


More information about the Distutils-SIG mailing list