Exec method with commands requiring input 
Author Message
 Exec method with commands requiring input

Hi,

I've a script that uses the Shell run command to run a Telnet session.
Then I use the Shell SendKeys command to provide the necessary input to
Telnet. No probs.

I need to capture some output from the Telnet session. So I thought to use
the Exec method and eventually capture data from StdOut. But can't make it
work. Either  the script hangs, waiting for input or spits out data at the
wrong place.

Is it possible at all, to use Exec method with commands requiring input ? I
searched MSDN, but no luck
If yes, any idea on how to correctly sequence the commands ? A small example
would be appreciated.

Thanks
Raymond



Thu, 22 Dec 2005 05:50:17 GMT  
 Exec method with commands requiring input

Quote:
> Hi,

> I've a script that uses the Shell run command to run a Telnet session.
> Then I use the Shell SendKeys command to provide the necessary input to
> Telnet. No probs.

> I need to capture some output from the Telnet session. So I thought to use
> the Exec method and eventually capture data from StdOut. But can't make it
> work. Either  the script hangs, waiting for input or spits out data at the
> wrong place.

> Is it possible at all, to use Exec method with commands requiring input ? I
> searched MSDN, but no luck
> If yes, any idea on how to correctly sequence the commands ? A small example
> would be appreciated.

Yes it's possible but its only useful if u work with pure
commandline executables (no gui) and if the executable expects
the input to come via the stdin file-handle (and not via
parameters or inputcontrols).
and you have to be careful with the read-commands.
because if you have 3 stdout.readline()-statements for example
but stdout only writes 2 lines, then the script will hang everlasting
waiting for the third line (so you always have to check EOF before
reading something and to make things worse, the EOF-property isn't
correctly set for stdout-textstreams on Win9x, thats why the
following example works on WinNT5+ but not on Win98)

set ws = createobject("wscript.shell")
set xc = ws.Exec("sort.exe")
set np = xc.StdIn
set op = xc.StdOut

For Each token in Split ("sorting an unsorted string")
  np.Writeline token
Next
np.Close

while not op.AtEndOfStream
   s = s & vbcrlf & op.ReadLine
wend
msgbox s

--
Gruesse,
Alex



Thu, 22 Dec 2005 07:42:02 GMT  
 Exec method with commands requiring input
Alex,

Clever trick !
I was still far from a workable solution (I'm not a programmer). I'll try to
adapt your example to my needs.

Thanks a lot
Raymond


Quote:

> > Hi,

> > I've a script that uses the Shell run command to run a Telnet session.
> > Then I use the Shell SendKeys command to provide the necessary input to
> > Telnet. No probs.

> > I need to capture some output from the Telnet session. So I thought to
use
> > the Exec method and eventually capture data from StdOut. But can't make
it
> > work. Either  the script hangs, waiting for input or spits out data at
the
> > wrong place.

> > Is it possible at all, to use Exec method with commands requiring input
? I
> > searched MSDN, but no luck
> > If yes, any idea on how to correctly sequence the commands ? A small
example
> > would be appreciated.

> Yes it's possible but its only useful if u work with pure
> commandline executables (no gui) and if the executable expects
> the input to come via the stdin file-handle (and not via
> parameters or inputcontrols).
> and you have to be careful with the read-commands.
> because if you have 3 stdout.readline()-statements for example
> but stdout only writes 2 lines, then the script will hang everlasting
> waiting for the third line (so you always have to check EOF before
> reading something and to make things worse, the EOF-property isn't
> correctly set for stdout-textstreams on Win9x, thats why the
> following example works on WinNT5+ but not on Win98)

> set ws = createobject("wscript.shell")
> set xc = ws.Exec("sort.exe")
> set np = xc.StdIn
> set op = xc.StdOut

> For Each token in Split ("sorting an unsorted string")
>   np.Writeline token
> Next
> np.Close

> while not op.AtEndOfStream
>    s = s & vbcrlf & op.ReadLine
> wend
> msgbox s

> --
> Gruesse,
> Alex



Thu, 22 Dec 2005 16:06:07 GMT  
 Exec method with commands requiring input
No luck ! Telnet doesn't work :-((
Your example works OK, indeed Sort works with > and <.

I'm re-reading your reply

Quote:
> if u work with pure commandline executables (no gui)

OK. That's the case

Quote:
>and if the executable expects  the input to come via the stdin file-handle

(and not via
I think that's the problem with MS Telnet W2K
Otherwise a dumb command
Telnet 10.0.0.138 < MyScript
would also work. Not the case
Beats me. I give up

Thanks a lot
Raymond



Thu, 22 Dec 2005 17:03:59 GMT  
 Exec method with commands requiring input
It would have helped to know that it was the telnet client
in the first place.

Telnet is NOT command line driven, though it is indeed a
pure console program.  Unfortunately, it takes command of
the console and gets its input directly from the keyboard
after it initializes.  One way communications (into the
telnet console) can be scripted using the Wscript.Shell's
Sendkeys method, but it is not too robust.  If anything
other than simple login sequence is desired, such as
processing responses, you are better off finding a
replacement (third-party) telnet client that is
scriptable.  There are several, though I have no URL handy
(don't use then).  Try a google search in the
ms.public.scripting.* groups for 'script' and 'telnet'.  
You'll probably get a good number of hits.

Tom Lavedas
===========

Quote:
>-----Original Message-----
>No luck ! Telnet doesn't work :-((
>Your example works OK, indeed Sort works with > and <.

>I'm re-reading your reply
>> if u work with pure commandline executables (no gui)
>OK. That's the case

>>and if the executable expects  the input to come via the
stdin file-handle
>(and not via
>I think that's the problem with MS Telnet W2K
>Otherwise a dumb command
>Telnet 10.0.0.138 < MyScript
>would also work. Not the case
>Beats me. I give up

>Thanks a lot
>Raymond

>.



Fri, 23 Dec 2005 20:41:48 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Exec ISAPI DLL from ASP (SSI command exec ?)

2. Using Scripting.Shell Exec command to capture the results of a SFTP ls command

3. Exec method

4. Help with Exec method

5. Exec Method Not Supported -- Wrong WSH Version?

6. No FTP output when launched with Exec method

7. Exec method syntax

8. FTP and Run vs Exec methods

9. Cannot synchronize with WSH Exec method

10. Wscript.Shell Exec method

11. WSH 5.6 Beta 1, new method, WScript.Exec

12. MultiThread an Exec Function passing Array Elements of Commands

 

 
Powered by phpBB® Forum Software