asked on
Dim strCmd As String = "echo Hello"
Dim strErr, strOut As String
' Set start information.
Dim start_info As New ProcessStartInfo(strCmd)
start_info.UseShellExecute = False
start_info.CreateNoWindow = True
start_info.RedirectStandardOutput = True
start_info.RedirectStandardError = True
' Make the process and set its start information.
Dim proc As New Process
proc.StartInfo = start_info
' Start the process.
proc.Start()
' Attach to stdout and stderr.
Dim std_out As StreamReader = proc.StandardOutput()
Dim std_err As StreamReader = proc.StandardError()
' Display the results.
strErr = std_out.ReadToEnd()
strOut = std_err.ReadToEnd()
' Clean up.
std_out.Close()
std_err.Close()
proc.Close()
MsgBox(strErr)
MsgBox(strOut)
ASKER
Sub logExec(strCommand)
'INPUT: strCommand = A command to run at a DOS prompt
'OUTPUT: The output of the resulting command sent to both the screen and the log file.
' This captures both the stdout stream and the stderr stream
dim objShell, objExecObject, strOutput
WScript.Echo strCommand
writelog "logExec", "Command: " & strCommand
Set objExecObject = oShell.Exec(strCommand)
writelog "logExec", "-------- Start LogExec Output --------"
Do Until objExecObject.StdOut.AtEndOfStream
strOutput = objExecObject.StdOut.ReadLine()
writelog "logExec", strOutput
WScript.Echo strOutput
loop
Do Until objExecObject.StdErr.AtEndOfStream
strOutput = objExecObject.StdErr.ReadLine()
writelog "logExec", strOutput
WScript.Echo strOutput
loop
writelog "logExec", "-------- End LogExec Output --------"
end sub
Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.
TRUSTED BY
it's capturing the error from cacls in vbscript
i dont know if it can capture a text, but it should get you on the way to find how to capture more
Open in new window