View Single Post
Old 08-07-2008   #2 (permalink)
mr_unreliable


 
 

Re: StdOut and StdErr reading...

lucadentella@xxxxxx wrote:
Quote:

> I'm working on a script to automate SFTP operations (using a text-
> based sftp client).
> My idea is to use the Exec() method to run the client, send commands
> via StdIn and receive output via StdOut and StdErr.
>
hi Lucadentella,

I can't say exactly what is going wrong with your
script, but I can say that stdin/out can get tricky.

In some cases a careful use of "sleep" can help,
that is, by allowing time for things to develop.

For example, if you run you app "manually", and
see some delays as it is working, then when you
script it, that would be the place (or places) to
insert your delay(s).

If nothing else, without any "sleep" calls (analagous
to vb's DoEvents) you may be "hogging-the-cpu", and
not allowing your other app (which is doing the "real
work") to have a chance at getting the cpu so it can
get going...

The following snippet of code did not work for me
until after I inserted the "sleep".

--- <code> ---
Set oExec = WshShell.Exec(sScriptFolder & "testCase.bat")
sInput = ""

Do While True

If Not oExec.StdOut.AtEndOfStream Then
' sInput = sInput & oExec.StdOut.Read(1) ' read one character
sInput = sInput & oExec.StdOut.ReadLine & vbCrLf
' WScript.Echo sInput
If InStr(sInput, "Press any key") <> 0 Then Exit Do
End If
WScript.Sleep 10
Loop

oExec.StdIn.Write vbCrLf
--- </code> ---

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)
My System SpecsSystem Spec