Pearl_export_ben
asked on
VBS Capture Command Output
Hi Folks,
The attached code is in a loop where everytime it runs, strcomputername is changed - thus shutting down multiple machines in a target list.
The problem I am having is that strcapture is always an empty carriage return when written out to the logfile. I know that if the machine shutdown is successful then the empty blank line returned is expected, but when i run the command against a machine name that doesn't exist, it should come back with an error like "The Network Path Was Not Found" or similar.
How can i get strCapture to capture the output correctly?
The attached code is in a loop where everytime it runs, strcomputername is changed - thus shutting down multiple machines in a target list.
The problem I am having is that strcapture is always an empty carriage return when written out to the logfile. I know that if the machine shutdown is successful then the empty blank line returned is expected, but when i run the command against a machine name that doesn't exist, it should come back with an error like "The Network Path Was Not Found" or similar.
How can i get strCapture to capture the output correctly?
strCommand = "shutdown -s -m \\" & strcomputername & " -t 00 -f"
Set objScriptExec = objShell.Exec(strCommand)
strCapture = objScriptExec.StdOut.ReadAll
LogFile.WriteLine(strCapture)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
thanks
You usually have to put in a loop to wait until the Exec has finished (Status = True), then read StdOut.
Open in new window