home *** CD-ROM | disk | FTP | other *** search
/ Chip: Windows 2000 Professional Resource Kit / W2KPRK.iso / apps / perl / ActivePerl.exe / data.z / runperl.bat < prev    next >
Encoding:
DOS Batch File  |  1999-10-16  |  2.3 KB  |  82 lines

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S "%0" %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. goto endofperl
  11. @rem ';
  12. #!perl -w
  13. #line 14
  14. $0 =~ s|\.bat||i;
  15. unless (-f $0) {
  16.     $0 =~ s|.*[/\\]||;
  17.     for (".", split ';', $ENV{PATH}) {
  18.     $_ = "." if $_ eq "";
  19.     $0 = "$_/$0" , goto doit if -f "$_/$0";
  20.     }
  21.     die "`$0' not found.\n";
  22. }
  23. doit: exec "perl", "-x", $0, @ARGV;
  24. die "Failed to exec `$0': $!";
  25. __END__
  26.  
  27. =head1 NAME
  28.  
  29. runperl.bat - "universal" batch file to run perl scripts
  30.  
  31. =head1 SYNOPSIS
  32.  
  33.     C:\> copy runperl.bat foo.bat
  34.     C:\> foo
  35.     [..runs the perl script `foo'..]
  36.     
  37.     C:\> foo.bat
  38.     [..runs the perl script `foo'..]
  39.     
  40.  
  41. =head1 DESCRIPTION
  42.  
  43. This file can be copied to any file name ending in the ".bat" suffix.
  44. When executed on a DOS-like operating system, it will invoke the perl
  45. script of the same name, but without the ".bat" suffix.  It will
  46. look for the script in the same directory as itself, and then in
  47. the current directory, and then search the directories in your PATH.
  48.  
  49. It relies on the C<exec()> operator, so you will need to make sure
  50. that works in your perl.
  51.  
  52. This method of invoking perl scripts has some advantages over
  53. batch-file wrappers like C<pl2bat.bat>:  it avoids duplication
  54. of all the code; it ensures C<$0> contains the same name as the
  55. executing file, without any egregious ".bat" suffix; it allows
  56. you to separate your perl scripts from the wrapper used to
  57. run them; since the wrapper is generic, you can use symbolic
  58. links to simply link to C<runperl.bat>, if you are serving your
  59. files on a filesystem that supports that.
  60.  
  61. On the other hand, if the batch file is invoked with the ".bat"
  62. suffix, it does an extra C<exec()>.  This may be a performance
  63. issue.  You can avoid this by running it without specifying
  64. the ".bat" suffix.
  65.  
  66. Perl is invoked with the -x flag, so the script must contain
  67. a C<#!perl> line.  Any flags found on that line will be honored.
  68.  
  69. =head1 BUGS
  70.  
  71. Perl is invoked with the -S flag, so it will search the PATH to find
  72. the script.  This may have undesirable effects.
  73.  
  74. =head1 SEE ALSO
  75.  
  76. perl, perlwin32, pl2bat.bat
  77.  
  78. =cut
  79.  
  80. __END__
  81. :endofperl
  82.