展示 Exec 對象的 stdin 輸入流。
Object.StdIn
使用 StdIn 屬性將數(shù)據(jù)傳遞到用 Exec 啟動的過程中。
下面的代碼啟動一個批文件后等待用戶輸入提示。通過 StdIn 流輸入所需數(shù)據(jù)之后該批文件結(jié)束。
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);