November 11, 2004

And People Thought I Was Crazy

Back at Cylant, I did practically all my build infrastructure, packaging, and installer work in a weird amalgam of Bourne shell, Perl, and Makefile. Naturally, I was the subject of many a comment about sadism (Heck, I was even known to debase myself for that combination...)

But working in a Windows environment, I find myself debasing myself to new and never before plumbed depths. CMD.EXE, how do I hate thee? Let me count the ways:

  • No control structures other than if, goto and for.
  • Variable access semantics are different depending on how and where the access occurs.
    Standard access to variable contents.
    %VARIABLE (or %%VARIABLE inside a .CMD file)
    Access to the current iteration of a for loop. (The double percents are actually to escape the percent sign, so the script parser won't try and substitute a variable.)
    Delayed expansion. Since each statement is parsed and executed individually, expand the variable at the point of execution, instead of when the statement is parsed. This has esoteric uses such as from within a for loop. (Not really all that esoteric if you think about it.)
  • It is impossible to capture the output of a command back into the current script. There is a echo-set/call idiom that seems to be prevalent as a workaround, but imagine how the elegant (well as elegant as Bourne shell can be):
    becomes the ugly idiom.cmd:
    if exist %temp%\passback.cmd (
        call %temp%\passback.cmd
        del %temp%\passback.cmd
    Plus, you have to modify subcall.cmd to add the following:
    echo set OUTVAR=%Result_I_pass_back% > %temp%\passback.cmd
    instead of just printing $Result_I_pass_back to standard out. &shudder;
  • Most non trivial text manipulation usually calls for shelling out to Perl. (Basically anything more complicated than perl's split builtin cannot be handled by CMD, but must be shelled out to perl with the results coming back to the script via the echo-set/call discussed above.)

I'm sure that if i sat down and really thought about it, I could come up with more things to dislike about it. No one ever accused me of being sane.

Posted by bbassett at November 11, 2004 12:22 PM