'---------------------------------------------------------------------
'-- 1998 © Pablo Almunia
'---------------------------------------------------------------------
'--
'-- Program : RunOutput.VBS
'-- Description : Funciont RunOutput run a programa and return the '-- output
'-- Parameters : cPrograma - Command to execute
'-- nWindowType - Type of windows (same Run method of '-- WScript.Shell)
'-- Notes : -
'-- Programer : Pablo Almunia
'-- Date : 03-03-1999
'-- Version : 1.0
'-- History : -
'--
'---------------------------------------------------------------------
Option Explicit
'-- Sample with a DIR
MsgBox RunOutput( "COMMAND /C DIR C:\", 0 )
'---------------------------------------------------------------------
'-- RunOutput Function
'---------------------------------------------------------------------
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
End Function
'--------------------------
'-- End of RunOutput.vbs --
'--------------------------
Credit: - 21/01/2001. |