Here is my code
Set objFSO = CreateObject("Scripting.FileSystemObject")
a = "@echo off && " & _
"pushd ""\\xxxxx.local\cfs\Development\Docs\Baseline"" &&" & _
"cls &&" & _
"dir /b /a-d &&" & _
"popd"
Set objShell = CreateObject("WScript.Shell").Exec("%comspec% /c " & a)
execStdOut = objShell.StdOut.ReadAll()
msgbox execStdOut
Basically I am trying to run Dir command on a network drive. It works fine, but the only issue is that the output contains a garbage character in the beginning. Not sure why?
Output
If I run the same steps in a batch file, the output is correct
The answer to your question is that
cls
is being captured by theStdOut
stream and interpreted as an extended character. Get rid of it. You don't need it.Just so I feel like I've done something, here's the script rewritten as a batch + JScript hybrid. Save it with a .bat extension if you want to mess with it.
As an added bonus, here's the same thing with a lovely "ding" noise added.