• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

IWshExec.StdIn Property

Started by José Roca, July 14, 2008, 08:45:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following code starts a batch file and waits for the user input prompt. After entering the needed data through the StdIn stream, the batch file will be able to complete.

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);


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


PowerBASIC

LOCAL pWsh3 AS IWshShell3
LOCAL pWshExec AS IWshExec
LOCAL pStdIn AS ITextStream
LOCAL pStdOut AS ITextStream
LOCAL strInput AS STRING

pWsh3 = NEWCOM "WScript.Shell"
IF ISNOTHING(pWsh3) THEN EXIT FUNCTION
pWshExec = pWsh3.Exec(UCODE$("test.bat"))

pStdOut = pWshExec.StdOut
IF ISNOTHING(pStdOut) THEN EXIT FUNCTION

DO
   IF pStdOut.AtEndOfStream THEN EXIT DO
   strInput = strInput & ACODE$(pStdOut.Read(1))
   IF INSTR(strInput, "Press any key") <> 0 THEN EXIT DO
   SLEEP 100
LOOP
pStdOut = NOTHING

pStdIn = pWshExec.StdIn
pStdIn.Write UCODE$($CRLF)
pStdIn = NOTHING

DO
   IF pWshExec.Status = 1 THEN EXIT DO
   SLEEP 100
LOOP

pWshExec = NOTHING
pWsh3 = NOTHING

PRINT "Done."
WAITKEY$


test.bat


@echo off
echo Press any key
pause