Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!eastapps!hiredgun!tdinger From: tdinger@hiredgun.East.Sun.COM (Tom Dinger - Sun BOS SPA) Newsgroups: comp.lang.perl Subject: Re: MS Perl Questions Summary: perlscript.BAT Message-ID: <4657@eastapps.East.Sun.COM> Date: 5 Mar 91 22:10:44 GMT References: <1991Mar1.041441.4810@ccu1.aukuni.ac.nz> <1991Mar4.165742.12909@holos0.uucp> Sender: news@East.Sun.COM Reply-To: tdinger@east.sun.com (Tom Dinger - Sun BOS SPA) Followup-To: tdinger@east.sun.com Organization: Sun Microsystems, Billerica MA Lines: 66 In article <1991Mar4.165742.12909@holos0.uucp> lbr@holos0.uucp (Len Reed) writes: >In article <1991Mar1.041441.4810@ccu1.aukuni.ac.nz> russell@ccu1.aukuni.ac.nz (Russell J Fulton;ccc032u) writes: >>Just one question. Is there and equivalent of #!.../perl for MS dos .bat files? >> >>I had some example files from a previous release of msperl (which I deleted >>since I don't have MS C) and these had >>some stuff: > >>@REM=(" >>@perl 0%.bat ... >>@end=") > >This often won't work, and it didn't really work in patch level 18 when d.d.s. >suggested doing it. "End" doesn't mean anything to command.com. (Perhaps >d.d.s. had a command.com that treated "end" as a directive to quit >interpreting the batch file'.) After perl runs, command.com starts >executing the perl lines after "@end" which often--but not always--gives >errors. > >I could not find a general solution to this problem. >-- >Len Reed >Holos Software, Inc. >Voice: (404) 496-1358 >UUCP: ...!gatech!holos0!lbr I have had success wrapping the perl script in the following sequence: @REM=(" perl -S %0.BAT %1 %2 %3 %4 %5 %6 %7 %8 %9 @goto end ") if 0 ; print "Howdy, world!\n"; @REM=(" :end ") if 0 ; If you are using a DOS version before 3.30, you have some problems, as the '@' character is not recognised as suppressing echo of the command, so you will get a DOS "unrecognized command" error for those lines. In this case, remove the '@' from the "goto" line, and the script will still work, (aside from the error message). Limitations of the above: 1. This will only work if you type the batch file name without an extension: If you enter the command "t.bat" to DOS, perl will look for "t.bat.BAT" and give the error "Can't execute t.bat.BAT". 2. The batch script must be in a directory on your PATH. The code in perl that searches the path does not start by default with the current directory, as DOS does. (Maybe I should post a patch for this -- it looks pretty easy, and would only apply to DOS). TD ------------------------------------------ Tom Dinger consulting at: TechnoLogics, Inc. Sun Microsystems Internet: tdinger@East.Sun.COM (508)486-8500 (508)671-0521 UUCP: ...!sun!suneast!tdinger Tom Dinger consulting at: TechnoLogics, Inc. Sun Microsystems Internet: tdinger@East.Sun.COM (508)486-8500 (508)671-0521 UUCP: ...!sun!suneast!tdinger