展示 Exec 对象的 stdin 输入流。
Object.StdIn
使用 StdIn 属性将数据传递到用 Exec 启动的过程中。
下面的代码启动一个批文件后等待用户输入提示。通过 StdIn 流输入所需数据之后该批文件结束。
Dim WshShell, oExec, input
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("test.bat")
input = ""
Do While True
If Not oExec.StdOut.AtEndOfStream Then
input = input & oExec.StdOut.Read(1)
If InStr(input, "Press any key") <> 0 Then Exit Do
End If
WScript.Sleep 100
Loop
oExec.StdIn
.Write VbCrLf
Do While oExec.Status <> 1
WScript.Sleep 100
Loop
var WshShell = new ActiveXObject("WScript.Shell");
var oExec = WshShell.Exec("test.bat");
var input = "";
while (true)
{
if (!oExec.StdOut.AtEndOfStream)
{
input += oExec.StdOut.Read(1);
if (input.indexOf("Press any key") != -1)
break;
}
WScript.Sleep(100);
}
oExec.StdIn.Write("\n");
while (oExec.Status != 1)
WScript.Sleep(100);