go ahead... be a heretic | |
PerlMonks |
Redirection with Win9x batch filesby footpad (Abbot) |
on Dec 09, 2000 at 00:12 UTC ( [id://45781]=perlquestion: print w/replies, xml ) | Need Help?? |
footpad has asked for the wisdom of the Perl Monks concerning the following question:
Momentarily setting aside any discussion of the merits of various operating systems, the apprentice requests feedback from the community regarding the following:
First off, I apologize for the length of the post. It's involved, but I've tried to be as brief as possible and I'd appreciate any feedback on a solution designed to make it easier to develop Perl scripts on my Windows machines. The additional detail is designed to help fill the gaps when necessary, as well as demonstrate that I've tried to do my homework. Like many of you, I prefer to debug my Perl scripts locally before uploading them to my server; since the bulk of my development work involves Windows, that means installing ActivePerl and configuring my Win9x development machine appropriately. If you have a more than passing familiarity with MS-DOS and the limitations of batch files, you know that a long PATH statement is less than ideal, especially if you have a number of software programs that require PATH entries (local database servers, 16-bit programs, certain application development command-line tools, various utilities, and so on). Over the years, I've gotten into the habit of using batch files to call various things on my system. By collecting these into a single directory, I've been able to keep my PATH small and reserve environment space for other uses. My first batch file for Perl looked like this:
This worked well, until I started trying to debug scripts that returned more than 25, 43, or 50 lines of output (corresponding to the sizes you can set your MS-DOS prompt to support). In *nix, you can redirect output to files or pipe it to display utilities very easily. This also works in DOS, but only if you call perl.exe directly (for batch files do not let you pass redirection or piping commands as parameters to programs in your batch files.) For example, you can't use something like: perlbat -V > stdout.logbecause the perlbat file assumes that it's supposed to handle this and doesn't pass that information to the program(s) called within the batch file. Because of the way I've configured my system, this means I need to type: c:\devt\perl\bin\perl -V > stdout.logto redirect the output. While I could type the extra seventeen characters when needed, this seemed like too much work. (laziness, impatience, etc). After getting some hints via CB a couple of days ago (thanks, Tilly) and reviewing relevant nodes found with Search (thanks to the posters), my perl.bat now looks like this:
My petitions are:
For clarity, here's a formatted version of the code being executed:
Note: if you wish to adapt the above into an external script, line 5 in the above needs to be changed to something along these lines: @args = qw( perl, @ARGV );Other notes for those wishing to adapt this for their use:
The alternate approach If the above approach doesn't appeal to you, here's an alternate batch file that works by "adding" a command-line option to your perl batch file to log STDOUT to a text file:
You'll not that while this lets you specify -L to log STDOUT, it doesn't log STDERR unless your script points STDERR to STDOUT using something along these lines: open STDERR, ">&STDOUT";(Credits and details here and here.) Also, there's a risk associated with this approach because it's entirely possible that future versions of Perl may include a -L switch. You'd have to rewrite your batch file in that case. For best results with either approach, you may find it helpful to use two batch files to run perl:
By doing so, you can take advantage of DOS's limited command repetition support, e.g.
In the end, choose the approach that works best for you and be sure to take any wisdom attached in any replies into account. --f
Back to
Seekers of Perl Wisdom
|
|