Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the reasons to use dos batch programs in Windows?

Question

What would be a good (ideally, technical) reason to ever program some non-trivial task in dos batch language on a modern Windows system as opposed to downloading either PowerShell, or ActiveState Perl?

To be more specific, I make the following two assumptions for the duration of this question:

  • anyone technical enough to be able to write a medium-complexity batch script is technical enough to install either of the scripting interpreters.

  • Neither of those two present enough of a learning curve for basic batch replacement tasks that said curve would outweigh the pain of doing any remotely-non-trivial task in batch.

Notes

  • "You need a batch program for autoexec.bat" is not a valid reason. Your autoexec.bat may consist of simply calling non-batch script.

  • If you disagree with either of my 2 assumptions above, that's fine, and I may be wrong. But my question is specifically "assuming those 2 assumptions are correct, what would be the reason to still stick with batch?" If it makes it easier to suspend disbelief (in case you disagree with me), add in a 3rd assumption that the question is limited to people who already posess at least some modicum of PowerShell or Perl experience.

    To re-iterate - this is not meant to be a subjective question about how easy it is to learn PSh or ASPerl compared to doing advanced batch coding. That is a separate question that is too subjective to be bothered with in this post.

Background:

I used to do some fairly complicated batch programming back in the elder days, and remember batch as one of the worst possible programming languages I had encountered.

The idea for this question came after seeing a bunch of batch questions on SO, and trying to grok the answer of one of them out of sheer curiosity and giving up in pain after a minute, exclaiming mentally "why would anyone go through this pain instead of doing that in 1 line of Perl?" :)

My own plausible answer

I assume there may be an an likely DOS-compatible system, which has DOS interpreter but has no compatible PowerShell or Perl... I'm not aware of one but not completely impossible.

like image 341
DVK Avatar asked Apr 03 '10 00:04

DVK


Video Answer


1 Answers

Typically, the rationale is that you need the script to run on a machine which does not have another interpreter and on which you are not allowed to install an interpreter. Production servers in many companies are a good example -- you want them to have as few exploitation vectors as possible, which means no scripting languages that are not required for application functionality.

You're right when you say that the batch language is a terrible language -- there's a reason they sunk the time and money into building PowerShell -- but it's also the only universal language you can rely on across the myriad versions of Windows.

like image 146
Dan Story Avatar answered Sep 21 '22 19:09

Dan Story