Skip to content

Instantly share code, notes, and snippets.

@pwlin
Created April 18, 2010 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwlin/370195 to your computer and use it in GitHub Desktop.
Save pwlin/370195 to your computer and use it in GitHub Desktop.
shell exec
' wsh shell execute and return output
' MsgBox RunOutput("COMMAND /C DIR C:\", 0)
Function RunOutput(cProgram, nWindowType)
'-- Obtain a Temporary File Name
Dim oFS
Set oFS = CreateObject("Scripting.FileSystemObject")
Dim cFile
cFile = oFS.GetSpecialFolder(2).Path & "\" & oFS.GetTempName
'-- Execute the command and redirect the output to the file
Dim oShell
Set oShell = CreateObject("WScript.Shell")
oShell.Run cProgram & " >" & cFile, nWindowType, True
Set oShell = Nothing
'-- Read output file and return
Dim oFile
Set oFile = oFS.OpenTextFile(cFile, 1, True)
RunOutput = oFile.ReadAll()
oFile.Close
'-- Delete Temporary File
oFS.DeleteFile cFile
Set oFS = Nothing
Set cFile = Nothing
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment