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