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