Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Run Command Capture Output
 

Vbscript / Processes And Services / Run Command Capture Output

This script provides a function to run a command using the Shell Execute method and capture/return the output as a string variable.


Wscript.Echo runCMD("ping 127.0.0.1")

Function runCMD(strRunCmd)

 Set objShell = WScript.CreateObject("WScript.Shell")
 Set objExec = objShell.Exec(strRunCmd)
 
 strOut = ""

 Do While Not objExec.StdOut.AtEndOfStream
  strOut = strOut & objExec.StdOut.ReadLine()
 Loop

 Set objShell = Nothing
 Set objExec = Nothing

 runCMD = strOut

End Function





Please note that a disclaimer applies to any code on this page.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
     - Exchange
     - Files And Folders
     - General
     - Ms Office
     - Operating System
     - Processes And Services
          - Computer Service Properties
          - End Process
          - Run Command Capture Output
          - Running Process Properties
          - Start Stop Service
     - Text Processing
     - User Interaction
     - Web Servers