Slashdot Mirror


For Automated Testing, Better Alternatives To DOS Batch Files?

An anonymous reader writes "I am working on a project that would allow our customers to test out sending different PCL commands to LAN printers. My initial thought was that a DOS batch file will allow users to select some simple options, send the tests to printers, and even generate a small web page which, when launched from the batch file, will provide email feedback on the tool. This all worked. To spice it up I added some ANSI color commands to the menus, though the implementation of that may prove tricky without resorting to .COM files or forcing the load of the ansi.sys via the command.com shortcut. And this implementation goes against my initial idea that I want the entire thing to be contained in a standalone batch file. My questions are: Is there a better option for this? Are DOS Batch files too 1990s to be taken seriously in 2010? The application needs to (1) be simple (2) be easy to update (3) be able to send PCL commands to LAN-attached printers and (4) allow email feedback. I don't know what other programming language would allow this and be as simple. I tend to think that I have found the best tool for the job but if you have another idea let me know. Call me crazy but I love DOS."

28 of 426 comments (clear)

  1. DOS Is dead use visual basic by Joe+The+Dragon · · Score: 5, Funny

    DOS Is dead use visual basic

    1. Re:DOS Is dead use visual basic by Anonymous Coward · · Score: 5, Funny

      DOS is dead, and no-one cares
      If there is a shell, I'll see you there

    2. Re:DOS Is dead use visual basic by game+kid · · Score: 5, Funny

      Visual Basic sucks. Get Firefox instead.

      --
      You can hold down the "B" button for continuous firing.
    3. Re:DOS Is dead use visual basic by v1 · · Score: 4, Informative

      +1 agree. VB is RAD (rapid application development), is very flexible, and is easy to use to make standalone apps. if you like programming in dos, you will love VB. For the use you are suggesting, it sounds ideal. you can basically have it be the gui front end for things you need to be done in dos (via vb, you don't need a folder full of com files for it to use)

      --
      I work for the Department of Redundancy Department.
    4. Re:DOS Is dead use visual basic by buchner.johannes · · Score: 5, Insightful

      It is important to know your alternatives (e.g. you have many scripting options through cygwin, python, perl), but:
      Use whatever works for you, and don't be ashamed just because it is not the current trend. You know your requirements (easy to maintain). Don't believe the people that say you have to rewrite everything.

      --
      NB: The message above might reflect my opinion right now, but not necessarily tomorrow or next year.
    5. Re:DOS Is dead use visual basic by Homr+Zodyssey · · Score: 4, Informative

      I often write stuff like this using javascript or vbscript, and run it with "cscript". Its included in WinXP and later, so there's no installation required -- just a js or vbs script file. So, it would function much like your Batch file but you'd have a more descriptive language to work with.

      I do think vbscript is da debbil. However, it does have its uses when it comes to interacting with Office documents.

    6. Re:DOS Is dead use visual basic by Anonymous Coward · · Score: 5, Funny

      Rebooting your computer into another OS to test a printer?

      Do you meatbags SEE why you're not commercially viable as developers?

    7. Re:DOS Is dead use visual basic by Bigjeff5 · · Score: 4, Insightful

      They're also all a thousand times more complex than DOS.

      Even simple VB Script is significantly more complicated than DOS batch files.

      My advice? If it's internal to the company and only a few users are going to use it, a batch file is fine. If you're selling it, or a lot of people are going to be using it frequently, take the time to write a simple VB app to do the job. Something like this is so easy it would only take you an afternoon to do even if you've never used VB before, and it will look a much more professional.

      If you want to just make a more professional looking wrapper for it, you can use shell commands in a VB app and not waste any of your work in the DOS script.

      --
      Security is mostly a superstition... Avoiding danger is no safer in the long run than outright exposure. - Helen Keller
    8. Re:DOS Is dead use visual basic by SpectreBlofeld · · Score: 4, Insightful

      It sounds to me like the current implementation is not only effective and clever, but is (Windows) version-independent, and doesn't require any installation of third-party tools or utilities.

      Dude, you've created the Holy Grail of software. Why are you looking for alternatives?

    9. Re:DOS Is dead use visual basic by fbjon · · Score: 4, Insightful

      Hardly a cardinal sin. I've made a few in my day with loops and multiple choices using labels and gotos and such. Declare all important variables upfront, comment reasonably, and give it the same amount of testing as you would in a "real" language. The fact that batch files have no dependencies is a pretty good advantage, and the interpreter is backwards compatible.

      Shell scripts under *nix may be more functional, but batch files are perfectly serviceable, as long as you don't go on insane writing sprees with them.

      --
      True confidence comes not from realising you are as good as your peers, but that your peers are as bad as you are.
    10. Re:DOS Is dead use visual basic by Random+BedHead+Ed · · Score: 4, Insightful

      I'm surprised no one has suggested the most obvious upgrade path from the DOS batch file, Windows PowerShell. It's the intended replacement for batch files, and basically looks like Perl, but a little more Windowsy. It's integrated with lots of .NET goodies and ActiveDirectory, but in many ways it will be familiar to DOS scripters.

  2. Re:perl? by steveg · · Score: 4, Interesting

    Even better Strawberry Perl

    --
    Ignorance killed the cat. Curiosity was framed.
  3. If It Works, It Works But Remember Your Customers by eldavojohn · · Score: 4, Insightful

    I don't know who your customers are ... is this a sort of IT mass production heavy printer thing you're producing? I'm guessing so if they're LAN printers but who knows? Anyways if you're shipping this thing to residences, give the tool to your parents or -- failing that -- someone age ~15 or ~65. Give them the documentation you have and do not say a word. See what they do with it and how intuitive it is to them and take notes while they're using it. Do they successfully test the printer or fail? If they fail, that's actually your failure. So know your audience and maybe rethink the tool. But assuming that your audience isn't afraid of a command line interface, go for it. I guess you could look into whether or not Powershell gives you any advantages (probably not). You're in a different world than I so that last suggestion may be off the mark.

    --
    My work here is dung.
  4. Powershell by Shados · · Score: 4, Interesting

    The modern way of doing shell scripting in Windows is now powershell, and most things are quickly moving toward that. Its not as integrated in the OS, but its damn close, and in many ways its better than alternative scripting languages (object piping instead of text piping, for example).

    Now if its the best thing for your requirement? I don't know. But if you're planning to stick to shell scripting, do yourself a favor and upgrade.

  5. Python would be my first choice. by jgritty · · Score: 4, Insightful

    Python would be my first choice.

  6. AutoIt? by Anonymous Coward · · Score: 5, Informative

    Its a great tool thats free, and has good GUI and has good scripting capabilities too:

    http://www.autoitscript.com/autoit3/index.shtml

  7. Hate to say it... how about vbs? by Anonymous Coward · · Score: 5, Informative

    Python is much easier to write and much more maintainable than a batch script. Unfortunately it can be unfeasible to require this dependency on Windows machines.

    Good dependency-free (albeit platform-specific) alternatives are .vbs (visual basic script) and .js. Both allow access to more modern dialog boxes etc. Either script should be executed under wscript.exe (windows scripting host) but I believe there is an automatic file association by default (at least for .vbs files).

    For a more modern alternative, try Powershell, however it is only present by default on Windows 7.

    1. Re:Hate to say it... how about vbs? by shutdown+-p+now · · Score: 4, Informative

      Indeed, Active Scripting with VBscript or JScript is the only alternative if it has to run without any extra dependencies. It's available as a stock component from at least Win2K (I believe it's actually Win98, but can't be bothered to check; and I'm certain about Win2K). And while VBScript is ugly, JScript is a rather decent interpreted implementation of Ecma-262, and has enough hooks to do the stuff that is required here. And it's infinitely better than DOS batch files, that's for sure.

  8. Re:perl? by BJ_Covert_Action · · Score: 5, Insightful

    I'll second this one. The place that I work runs almost all of its commands via bat jobs that run from simple to complex. When I started here, I installed Strawberry Perl on my win32 system. I have, since, replaced every functionality that the bat jobs used to do with perl scripts (primarily for my own purposes, but most of my coworkers don't mind them either). The primary reason I did this was readability. I can set up my perl scripts in such a manner that I can look at them a year later and know exactly what I did and how I did it. All I had to do was be a little disciplined about script formatting and variable names (it's really not that hard).

    So far, I've gotten Strawberry perl to print to all of the printers on my network, run some old fortran programs successfully, update an in-house wiki automatically, automate e-mails to my co workers, and crash our entire network (that last one wasn't so much a feature, but hey, it shows just how powerful perl is). That said, I think with a bit of time and research you could probably get Strawberry perl to do exactly what you needed pretty easily. But I will warn you, when it comes to perl, I find that user experiences vary greatly.

  9. Re:perl? by BJ_Covert_Action · · Score: 5, Informative

    Oh, I should caveat one thing. In order to develop perl scripts into a distributable, platform independent, one click executable, I've been using the PAR packager module for perl. Sometimes it produces slightly bloated .exe's (since it has to bring in all of the relevant code from any external modules and dependencies), but it seems to produce very stable executables on win32 systems.

  10. I have a saying by buss_error · · Score: 5, Insightful

    "If it's stupid and it works, it's not stupid."

    There are plenty of doges you can use, perl, python, bash, and lots more. But all of them add a level of complexity to this that the batch file doesn't have. Which leads me to my second saying:

    "If it's simple and it works, it's elegant."

    Sounds like you've found an elegant solution to a problem. I'd stick with it if it works for you.

    --
    Necessity is the plea for every infringement of human freedom. It is the argument of tyrants; it is the creed of slaves.
  11. If .bat will do it, stick with .bat! by Anonymous+Freak · · Score: 5, Insightful

    PowerShell is the new Batch File Scripting, so if you need more power, learn PowerShell and use that. (I am assuming you're in a Windows environment where change of OS isn't an option.)

    But DOS batch files still work just fine. In my last job at $major-hardware-vendor, we used DOS batch file-based menus all the time; because they were simple, they got the job done, and all the people who had any need to maintain them knew all about them. Some were particularly large/gnarly batch files, too. (Think 3 KB of one single .bat file menuing to do a few dozen tasks.) When choice is used liberally, along with variables, you can make it very simple to maintain, too. (We used it for updating various things, and the very first section was where all the variables were set, all you had to do when it came time to update was throw the updated file in the right place, and change a number in the batch file.)

    --
    Another non-functioning site was "uncertainty.microsoft.com."
    The purpose of that site was not known.
  12. Assuming nobody is whining... by fuzzyfuzzyfungus · · Score: 4, Insightful

    Why would you consider messing with something that works?

    Your description suggests that, for anybody who doesn't really want to get their hands dirty, there is an adequate if rather retro menu driven interface. Great. A little reading never hurt anybody important.

    Even better, if your application is written within the limitations of CMD batch files, it'll be trivial for any admin who cares and has a copy of notepad to pick it apart, if needed.

    I, for one, fucking hate shiny-but-opaque vendor tools("Oh, great, you made it so easy that a trained monkey could do it, once. I need to do it 10,000 times, I see that your only officially supported method is '10,000 trained monkeys'. Would it have killed you to include some useful command-line options?". If your application is "send PCL test commands to networked printers" you ain't selling to grandma and cousin jim-bob. You may well be dealing with somebody who might need to programmatically test dozens or hundreds of printers. He will appreciate being able to rework your tool.

    CMD sucks; but it ships with every version of Windows since ever, and(since you've already written your application) apparently its limitations didn't cripple you. Why mess with it?

  13. If you do use VB... by transporter_ii · · Score: 4, Informative

    Did some quick research on it and it does look like it would work. But I did find this information:

    http://www.tek-tips.com/viewthread.cfm?qid=655463&page=6

    But here's the problem.... usually, when you use the printer object in VB to print with, it puts MORE PCL code round what you send (or PostScript, depending on the driver you use) and that messes the whole thing up.

    So one of my colleagues found a reference at MicroSoft on how to do what they call Raw Printng, which is direct to the printer not thru' the driver. We experimented with it and it does work. Here's the url: http://support.microsoft.com/support/kb/articles/Q154/0/78.asp

    --
    Doctors destroy health, lawyers destroy justice, universities destroy knowledge, religion destroys spirituality
  14. Re:He's right. by Anonymous Coward · · Score: 4, Informative

    AutoHotKey or AutoIt are better and they are free unlike Visual Basic.

  15. Powershell or VB Script w/ hta by KevMar · · Score: 5, Informative

    I would also look to Powershell to solve his issue.

    Before Powershell, I would have went with VB Script.

    Because he was wanting a bit more of a GUI, HTA (HTML Application) would be a simple option. It is a local web page named .hta instead of .html and it runs with application security on the local computer. Any script you can put in a .vbs file, you can also put into a script block of a .hta. This is one of those little tricks that not to many people know about.

    I use hta when I want to keep the flexibility of html/script as an alternative to a compiled vb.net app.

    --
    Im a gamer, not a grammer major. This post is full of spelling and grammer mistakes.
  16. Re:He's right. by kelsey.grammer · · Score: 5, Informative

    AutoHotKey or AutoIt are better and they are free unlike Visual Basic.

    Mod this up. I've used C++, Java, Perl, Ruby, vbscript, batch, and likely a few more to do this kind of thing in Windows over the years. For something this small I haven't found anything that beats AutoIt. It's so easy to learn and is fantastic for creating small, standalone executables with a GUI on Windows. This task is a perfect fit.

    --
    I reflect your pompous signature back upon you.
  17. Re:He's right. by teridon · · Score: 4, Informative

    AutoIt is nice -- the first time. That's how they hook you.

    Then, a year later, you decide to update your program. And hey, why not update to the latest version of AutoIt while you're at it? There was this one bug that always annoyed you, and you hope the devs fixed it.

    Well, guess what? While you had your back turned, all the APIs for the GUI changed. All those calls you made to AwesomeFunction() now require 4 arguments instead of 3. Oh, and one of them is now an object instead of string.

    That was my personal experience, anyway. After wroting a GUI program with perhaps 3000 lines of code, I updated to the new version of AutoIt. It seemed I had to practically rewrite the entire thing. Since then, I haven't recommended AutoIt to anyone that I like.

    --
    I hold it, that a little rebellion, now and then, is a good thing. -- Thomas Jefferson