Vbscript 管道脚本vbs
我创建了以下脚本,但它只返回0,甚至在DNS测试中发现错误Vbscript 管道脚本vbs,vbscript,Vbscript,我创建了以下脚本,但它只返回0,甚至在DNS测试中发现错误 Dim consult, objShell Set objShell = WScript.CreateObject ("WScript.shell") consult = objShell.run ("dcdiag /test:DNS | findstr /i failed", 0) If consult = "0" THEN WScript.Echo "OK" else WScript.Echo "ERROR"
Dim consult, objShell
Set objShell = WScript.CreateObject ("WScript.shell")
consult = objShell.run ("dcdiag /test:DNS | findstr /i failed", 0)
If consult = "0" THEN
WScript.Echo "OK"
else
WScript.Echo "ERROR"
end If
我知道那不是在运行findstr
感谢关注。- 您不使用“选项显式”;那太鲁莽了
- 您不会在Dims附近/之后立即启动;这很容易出错
- 只需使用一次变量(objShell);那太浪费了
- 在比较中混合数据类型(整数与字符串);那太愚蠢了
- 你没有仔细阅读文件;那太无礼了
Option Explicit
Dim consult : consult = WScript.CreateObject("WScript.Shell").Run("%comspec% /c ex0.vbs | ex1.vbs", 0, True)
If consult = "0" THEN
WScript.Echo consult, "OK"
else
WScript.Echo consult, "ERROR"
end If
输出:
cscript 36531325.vbs
1 ERROR
使用
查看您是否需要一个shell(%comspec%)来使用shell的功能(|)和
了解bWaitOnReturn参数的重要性。- 您不使用“选项显式”;那太鲁莽了
- 您不会在Dims附近/之后立即启动;这很容易出错
- 只需使用一次变量(objShell);那太浪费了
- 在比较中混合数据类型(整数与字符串);那太愚蠢了
- 你没有仔细阅读文件;那太无礼了
Option Explicit
Dim consult : consult = WScript.CreateObject("WScript.Shell").Run("%comspec% /c ex0.vbs | ex1.vbs", 0, True)
If consult = "0" THEN
WScript.Echo consult, "OK"
else
WScript.Echo consult, "ERROR"
end If
输出:
cscript 36531325.vbs
1 ERROR
使用
查看您是否需要一个shell(%comspec%)来使用shell的功能(|)和
用于理解bWaitOnReturn参数的重要性
.Run("%comspec% /c ex0.vbs | ex1.vbs", 0)