Accessing the Output of an External Command Executed in a DIAdem Script

Updated May 8, 2023

Environment

Software

  • DIAdem

I am developing a script in Diadem. I want to execute an external command, and to have access to the output of this command after it has finished. How can I achieve this?

You can execute any application or command using Windows' Scripting Host's shell.exec method.

The following snipped shows its usage by executing a demo command:
Option Explicit
dim myShell
set myShell = CreateObject("Wscript.Shell")
dim shellExec
set shellExec = myShell.exec("cmd /c dir c:\")
do while shellExec.Status = 0 '0: task is still running
  call pause(0.1)
loop
if shellExec.Status=1 then '1: task has finished
   msgbox shellExec.stdout.ReadAll
end if

Additional Information

The command used in the example above contains cmd /c, as the dir command is not a standalone command realized in its own executable file, but a command that is built into the command interpreter cmd.exe.

If you do not need access to the return values of the application, but want to have more control over the appearance of the called application's window, use the WScript.Shell.Run command instead. See the article titled "How Can I Execute an External Program from a DIAdem Script?" for more information.