2010-12-07 22 views

Répondre

7

Je doute que vous pouvez obtenir des fenêtres pour accepter un shbang (#!). Donc, si vous pouvez exécuter avec le shell par défaut (dans mon cas bash), cela fonctionne en bash:

@REM <<:END_REM 
@echo off 
echo This is DOS, this will only run in DOS. 
perl -x -S %0 %* 
goto over_nix 
:END_REM 
echo This is *NIX, this will only run in *NIX. 
perl -x -S $0 $* 

:<<__END__ 
#!perl 
use 5.012; 
use Data::Dumper; 

say Dumper(\%ENV); 

__END__ 
@REM <<:over_nix 
:over_nix 

Cela a nécessité un exécutable sur mon chemin NIX appelé '@REM'.

echo >> ~/bin/@REM 
chmod +x ~/bin/@REM 
+0

Clever, je l'aime bien. – Sorpigal

+0

FYI, il m'a fallu une minute pour comprendre comment l'utiliser mais vous voulez insérer votre programme perl entre les lignes END. Vous pouvez aussi mettre @REM dans le répertoire courant tant que vous avez le répertoire courant dans votre PATH. A travaillé super! – slm

3

Vous voulez dire comme ces wrappers fournis avec ActiveState Perl?

@rem = '--*-Perl-*-- 
@echo off 
if "%OS%" == "Windows_NT" goto WinNT 
perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9 
goto endofperl 
:WinNT 
perl -x -S %0 %* 
if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl 
if %errorlevel% == 9009 echo You do not have Perl in your PATH. 
if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul 
goto endofperl 
@rem '; 
#!perl 
#line 15 
    eval 'exec Z:\Software\Perl\5.8.8\bin\perl.exe -S $0 ${1+"[email protected]"}' 
    if $running_under_some_shell; 
#!/usr/bin/perl 
# $Id: cpan,v 1.3 2002/08/30 08:55:15 k Exp $ 
use strict; 

=head1 NAME 

cpan - easily interact with CPAN from the command line 

Le script se termine par ces lignes:

1;  
__END__ 
:endofperl 

bien que je ne suis pas sûr que vous avez vraiment besoin de l'étiquette BAT « : endofperl » à la fin ou dans la partie supérieure « goto endofperl » (pourrait utiliser une "sortie"?).