I recently ran into an issue where a WSH script was calling an external executable and returning an exit code of 0 even though there had been an error running the external executable. The problem is that I was relying on oExec.StdOut.ReadAll() to block the script until the command had finished processing. The ReadAll() method functions synchronously, so if the executable had been writing to StdOut, I would have been right. Unfortunately, I was neglecting the StdErr stream. So, not only did I miss the errors that the executable threw, the script didn’t block on the executable’s output, so I returned the exit code before the executable had actually finished running. The lesson here is to always think about StdErr no matter what you’re trying to accomplish.
Don’t forget StdErr
Leave a reply