Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


August 11, 2006

Save Time and Aggravation with These Debugging Tools

RSS
Subscribe to Windows IT Pro | See More Tips Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

In scripts, calls to external programs are useful, yet challenging to debug. These calls make many tasks possible, ranging from simple tasks (such as stringing together commands) to complex tasks (such as joining several specialized programs so that they work as a unit). Many complications can arise to increase the challenge:

  • The external program might run so quickly that it can't be visually observed.
  • The external program might take a long time to run and change files, which adds to the effort required to repeat a test.
  • The external program might need parameters that contain embedded spaces or other special characters that might get mangled, misplaced, or stripped, either by the calling script or the Windows shell.
  • The parameters might be provided on the fly.

To debug calls to external programs, I created a stand-in program named WinDummy that you can call in place of the real program. WinDummy parses the command line and lists the parameters exactly the way the real program will see them. Figure 1 shows an example. The command used to generated the results shown in Figure 1 is

WinDummy.exe Arg1 Arg2 
  "Spaces in Argument 3" Arg4 

(Although this command appears on several lines here, you would enter it on one line in the command-shell window. The same holds true for the other multiline commands in this article.)

When you click the OK button in Figure 1 to close the dialog box, Win-Dummy ends and the execution of the calling script continues as if the real program had just ended. Although the output from the real program won't be there, you'll know for sure that the program call works and that the parameters are correct.

If your script calls several programs, you can copy and rename WinDummy as many times as needed. You can run WinDummy from any directory because it requires no support files.

I also created a companion program, WWSimStatus, that simulates status codes returned by external programs, such as xcopy.exe. You use WWSimStatus in much the same way as Win-Dummy. Figure 2 shows an example of WWSimStatus. The command that generated the results shown in Figure 2 is

WWSimStatus.exe 123 

With WWSimStatus, you have an easy, safe way to simulate any status code generated by an external program.

You can use WinDummy and WWSimStatus to test any script that calls an external program, including VBScript, Perl, and Windows shell (.bat and .cmd) scripts. You can also use WinDummy and WWSimStatus to test programs such as Visual Basic for Applications (VBA) macros and custom standalone programs written in Visual Basic (VB), C, or any other programming language. Here are some examples of how you might use Win-Dummy and WWSimStatus:

  • Suppose you're testing a script that contains the statement
    If Exist File1.doc 
      MyProgram docname= File1.doc 

    You suspect that MyProgram isn't being passed the File1.doc parameter correctly. So, you run the command

    WinDummy.exe 
      docname= File1.doc 

    WinDummy's results show that the File1.doc parameter is being read as the second of two parameters rather than as part of the first parameter because of the embedded space.

  • Suppose that your script uses two programs: PgmA and PgmB. Your script calls PgmA, which in turn, calls PgmB. You suspect that PgmB isn't running, but it's hard to tell for sure because PgmB takes less than a second to run. By substituting WinDummy for PgmB in the script, you confirm your suspicion.
  • Suppose you have a batch script that uses a program named StatGen. StatGen returns a status code of 100 under rare conditions that are difficult to simulate. When StatGen returns status 100, your batch script does something special and you want to test that part of the script. By substituting WWSimStatus for StatGen, you can simulate any status code returned by StatGen. If StatGen returns several status codes and each status code requires a different action, you can use WWSimStatus to verify the correctness of your error-processing logic.

Since its creation in 2002, WinDummy has earned its keep. Before long, I expect to feel the same way about WWSimStatus. Both programs are freeware. WinDummy is available at http://www.wizardwrx.com/FREEBIES/WinDummy.html. WWSimStatus is available at http://www.wizardwrx.com/FREEBIES/WWSimStatus.html. You can also download these programs from the Windows Scripting Solutions Web site. See page 1 for download information. I hope that these programs can save you many hours and much grief.

—David Gray

End of Article



Reader Comments

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Understanding File-Size Limits on NTFS and FAT

A general confusion about files sizes on FAT seems to stem from FAT32's file-size limit of 4GB and partition-size limit of 2TB. ...


Scripting Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events WinConnections and Microsoft® Exchange Connections

7 Ways To Get More From Your SharePoint Deployment Now

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement