| Article: |  4935 of comp.lang.perl | 
| Path: |  theseas!dds | 
| From: |  dds@theseas.ntua.gr (Diomidis Spinellis) | 
| Newsgroups: |  comp.lang.perl | 
| Subject: |  Re: Perl script in Msdos batch file | 
| Message-ID: |  <1302@daidalos.theseas.ntua.gr> | 
| Date: |  6 May 91 15:21:58 GMT | 
| References: |  <1740@targon.UUCP> | 
| Organization: |  National Technical University of Athens | 
| Lines: |  49 | 
| Content-Length: |  2089 | 
In article <1740@targon.UUCP> andre@targon.UUCP (andre) writes:
>Now that we have perl also running on msdos, I thought up a way to put
>perl script inside msdos batch files in the same way we do in sh scripts.
[...]
>@echo = off ; 
>
>@rem = " MSDOS TO PERL STARTUP LINE
>perl -S %0.bat %1 %2 %3 %4 %5 %6 %7 %8 %9
>goto :end
>" if (0);
[...]
>@rem = " MSDOS TO PERL STARTUP LINE
>:end
>rem ";
>----Cut Here----
>My question is, do you see problems with this solution?
The most important problem is that you can not redirect input / output 
to / from perl scripts, because of the way MS-DOS handles batch files.
In order to write the standard output of a perl script into a file 
you still have to execute ``command /c perl_script >file''.  Command.com
will then handle I/O redirection.
>Has it been done earlier?
Yes.  This method is mentioned in the README file in the msdos directory
of the Perl distribution.
>Can it be done better or more elegant? (this works on msdos 3.3
>script must be in your path, not just .)
You can remove the trailer by adding an empty file called end.bat 
in your path.  Batch files run in a chain and not as subroutines under
MS-DOS (unless you use call) and for this reason your program will
terminate by running the end program.  The header can then be shortened to:
@rem ="
@perl -S %0.bat %1 %2 %3 %4 %5 %6 %7 %8 %9
@end " if (0);
(A small bit of history here:  The trick with the end.bat file was
discovered by mistake while trying to find a way to exit in the middle
of the batch file.  After I tried `exit' and `return' I tried `end'
which worked, only because, for some obscure reason, there was an
end.bat file in my path.  I thought it was an MS-DOS command, so I
didn't mention the need for the end.bat file in the MS-DOS Perl README
file.  When people started complaining that this trick was not working
on their machines I concluded that this was a peculiarity of the Compaq
3.31 MS-DOS.  Finaly someone suggested the need for the end.bat file.)
Diomidis Spinellis <dds@theseas.ntua.gr>
Newsgroup comp.lang.perl contents 
Newsgroup list 
Diomidis Spinellis home page
 
Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-Share Alike 3.0 Greece License.