Question:
How can I return the results of a WSH – Windows Script Host (WScript Object) script fired via Elipse E3? For example: can I retrieve the resulting string of a command executed via Command Prompt?
Solution:
Yes, you can return the results of a WSH script fired via Elipse E3. To do so, you must first understand what the Windows Script Host is, and how it works.
The Windows Script Host, also known as “WSH”, is a comprehensive script infrastructure for theMicrosoft® Windows® platform. There are two Windows Script mechanisms available for scripting: Visual Basic® Scripting Edition and Microsoft JScript®. Both these tools allow you to develop different types of scripts in order to accomplish various tasks inside the Windows environment. And since the WSH environment can be expanded, you can also use other programming languages for it, such as Python, for example.
It also includes several automation methods that are compatible with COM platform, thus allowing you to perform taks via the WSH objects model.
Therefore, in order to return the string that contains the executed result of the command via Elipse E3 prompt, we will create a WshShell object, using Exec() method StdOut.ReadAll function:
Sub CommandButton2_Click() strCMD = "Xcopy ""C:SourceDoc1.txt"" ""E:Destination"" /Y" Set WshShell = CreateObject("WSCript.shell") strReturn = WshShell.Exec(strCMD).StdOut.ReadAll msgbox strReturn End Sub
Example with ping command:
Sub CommandButton1_Click() strCMD = "ping 192.168.8.8" set WshShell = CreateObject("WScript.Shell") strResult = WshShell.Exec(strCMD).StdOut.ReadAll MsgBox strResult End Sub