Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.2 KiB

  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. =head1 NAME
  27. runperl.bat - "universal" batch file to run perl scripts
  28. =head1 SYNOPSIS
  29. C:\> copy runperl.bat foo.bat
  30. C:\> foo
  31. [..runs the perl script `foo'..]
  32. C:\> foo.bat
  33. [..runs the perl script `foo'..]
  34. =head1 DESCRIPTION
  35. This file can be copied to any file name ending in the ".bat" suffix.
  36. When executed on a DOS-like operating system, it will invoke the perl
  37. script of the same name, but without the ".bat" suffix. It will
  38. look for the script in the same directory as itself, and then in
  39. the current directory, and then search the directories in your PATH.
  40. It relies on the C<exec()> operator, so you will need to make sure
  41. that works in your perl.
  42. This method of invoking perl scripts has some advantages over
  43. batch-file wrappers like C<pl2bat.bat>: it avoids duplication
  44. of all the code; it ensures C<$0> contains the same name as the
  45. executing file, without any egregious ".bat" suffix; it allows
  46. you to separate your perl scripts from the wrapper used to
  47. run them; since the wrapper is generic, you can use symbolic
  48. links to simply link to C<runperl.bat>, if you are serving your
  49. files on a filesystem that supports that.
  50. On the other hand, if the batch file is invoked with the ".bat"
  51. suffix, it does an extra C<exec()>. This may be a performance
  52. issue. You can avoid this by running it without specifying
  53. the ".bat" suffix.
  54. Perl is invoked with the -x flag, so the script must contain
  55. a C<#!perl> line. Any flags found on that line will be honored.
  56. =head1 BUGS
  57. Perl is invoked with the -S flag, so it will search the PATH to find
  58. the script. This may have undesirable effects.
  59. =head1 SEE ALSO
  60. perl, perlwin32, pl2bat.bat
  61. =cut
  62. __END__
  63. :endofperl