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
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.