views:

214

answers:

5

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.

+8  A: 

Because I work at a bank where the default browser is IE6 on Windows XP and I have no idea if I'll be able to install PowerShell on someone's computer and I have a batch file which they can use to quickly and easily:

sqlcmd with some pre-import SQL
bcp
sqlcmd with some post-import SQL

With the whole batch needing to be RUNAS /NETONLY because the workstation does not participate in the domain that the SQL Server is on/trusts.

Not that I'm complaining or anything...

And I would say they are non-trivial because sometimes they take parameters and they require some pretty crazy escape quoting.

Cade Roux
+11  A: 

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.

Dan Story
Hmm... guess I'm so un-used to seing "producion" and "Windows" in the same sentense, having all my life existed in Unix/Linux world as far as production goes, didn't even think of that. +1
DVK
Shockingly, there are in fact companies that use Windows as a server platform. Sometimes it even works.
Dan Story
Heck, our company does. I just had the good (I assume) fortune to never touch that side of the Force at work. The closest I came was being a NETWARE admin back in college days :)
DVK
To be honest, Windows actually works really well as a server platform. The bad rap it gets (these days, at least) isn't so much the fault of the OS as it is the people who usually maintain it. UNIX admins tend to come from a rough-and-tumble command line world; Windows admins often come from desktop support and have trouble with anything that's not point-and-click.
Dan Story
although DOS is "universally" available since ancient times till now, but syntax changes and omission of some batch tools in newer versions often breaks batch code if you are going to port your old code to new. Its not "universal" after all.
@levis: Any examples of essential commands you're missing? Most of my batch code is entirely batch with no reliance on external programs. Occasionally there's a `findstr` or `find` but those two are unlikely to go away.
Joey
@DVK Can there be life after administering Netware?
Sinan Ünür
@Sinan - Ever heard of Nazgûl? :) That's from NETWARE, not some dinky rings :)
DVK
+4  A: 

I have a contract at a major utility company which absolutely does not allow unapproved programs on their computers. That would be expected of computers attached to the innermost networks which connect between control computers and devices, but the ban applies to the general purpose and administrative networks too.

The approved operating system is Windows XP SP3 with IE6. Upgrading is not allowed until technical support blesses it. Which, it seems, still may be some years from now.

Therefore, batch files are the only general scripting tool available. Some developer machines have access to C++ compilers, but the resulting programs are not permitted for internal distribution until the conclusion of a (probable multi-year) validation effort.

wallyk
So they allow unvalidated batch scripts but not unvalidated C++ code with identical functionality? Sad but not surprising :)
DVK
Shhhh! I would not be the least bit surprised if they added a ban for *unapproved batch files*—if they became aware of them.
wallyk
@wallyk - you make it sound like that'd be a BAD thing? Next time your electricity shuts off for a day 'cause some Yahoo ran untested crappy code on power company's network, I'm sure you'll want to worse to them than merely force their code go through code review from then on...
DVK
+2  A: 

You could also choose to use vbscript or jscript rather than perl and you wouldn't need to worry about installing any additional software.

Arle Nadja
Done that with JScript.
Axeman
The Windows Script Host may be disabled with group policies, though.
Joey
A: 

various reasons

  1. Its company policy, be it for security or other illogical reasons given by management, that you strictly use DOS.
  2. You had to support some legacy DOS scripts already written.
  3. You or the admins in the company only know DOS and have no capacity to learn other languages.
  4. You are coding for part of a larger DOS program already written
  5. Doing things the "harder" way make you look cool.
  6. You have a lot of time on your hands to devise workarounds for some things that are difficult to do easily with DOS
I severely doubt DOS is an issue anywhere currently. We're past that times for over a decade now and it doesn't even exist anymore on 64-bit Windows.
Joey