vbs调用exec执行dos命令之诡异细节

情况一 没有“cmd /c ”开头去执行dos命令(dos命令带有管道操作符和其他命令),单独一个dos命令有没有cmd开头貌似都没啥异常

Set oExec=WshShell.exec(" netstat -ano|findstr 843")

Set oStdOut = oExec.StdOut
strLine = oStdOut.ReadLine

此时strline 为空。也就是oStOut里面没有接受到东西。

情况二 加上“cmd /c ”

Set oExec=WshShell.exec("cmd /c netstat -ano|findstr 843")

Set oStdOut = oExec.StdOut
strLine = oStdOut.ReadLine

此时strLine 就有内容了。

原文地址:https://www.cnblogs.com/gyzhouyong/p/4548957.html