Windows 脚本宿主  

StdIn 属性 (WshScriptExec)

展示 Exec 对象的 stdin 输入流。

Object.StdIn

参数

Object
WshScriptExec 对象。

说明

使用 StdIn 属性将数据传递到用 Exec 启动的过程中。

示例

下面的代码启动一个批文件后等待用户输入提示。通过 StdIn 流输入所需数据之后该批文件结束。

[VBScript]
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
[JScript]
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);

请参阅

WshScriptExec 对象 | StdIn 属性 | StdErr 属性