Leaked source code of windows server 2003
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.

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