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

Hi everyone,

I am stuck trying to figure out why the Exec command of
Wscript.Shell does not seem to capture the output of a
SFTP ls command...

Here is the code:

Dim strStdOutLine, intSize, arrFolderNames()
Dim objShell

Set objShell = CreateObject("Wscript.Shell")
Set objPipe = objShell.Exec("%COMSPEC% /C ""(echo ls &

intSize = 0
While Not objPipe.StdOut.AtEndOfStream
  strStdOutLine = objPipe.StdOut.ReadLine()
  Wscript.Echo strStdOutLine
Wend

Somehow some of the output disappears... see below:
--START
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights
reserved.

Computer Usage Disclaimer

All activity may be monitored. System use indicates
consent to monitoring. Information may be given to law
enforcement.
sftp> ls

sftp> quit

--END

As you can see the results of all sftp commands are not
correctly output...  I have tried assigning certain lines
to an array using a regexp to test which lines I wish to
capture and I get funky results...  Could this be caused
by the fact that FTP uses a control port (for commands)
and a data port (for data) and somehow the data info gets
lost in the objPipe object????

Any help greatly appreciated... trying to figure this one
out and could really use your help!!!

Cheers,
David



Tue, 18 Jan 2005 06:52:22 GMT  
 Using Scripting.Shell Exec command to capture the results of a SFTP ls command
Actually, this seems to happen only when we append
something to it as in:

[...]
While Not objPipe.StdOut.AtEndOfStream
  strStdOutLine = objPipe.StdOut.ReadLine()
  Wscript.Echo strStdOutLine & " <-- This text overwrites
the output of strStdOutLine as if it was pasted on top..."
Wend
[...]

So if I entered just a couple of letters (e.g. ABC) and
the valid output was:

  MyDocuments

The funky output if I used the code above would be:

  ABCocuments

If I type enough characters the entire output would be
overwritten...

Thanks!
David

Quote:
>-----Original Message-----
>Hi everyone,

>I am stuck trying to figure out why the Exec command of
>Wscript.Shell does not seem to capture the output of a
>SFTP ls command...

>Here is the code:

>Dim strStdOutLine, intSize, arrFolderNames()
>Dim objShell

>Set objShell = CreateObject("Wscript.Shell")
>Set objPipe = objShell.Exec("%COMSPEC% /C ""(echo ls &

>intSize = 0
>While Not objPipe.StdOut.AtEndOfStream
>  strStdOutLine = objPipe.StdOut.ReadLine()
>  Wscript.Echo strStdOutLine
>Wend

>Somehow some of the output disappears... see below:
>--START
>Microsoft (R) Windows Script Host Version 5.6
>Copyright (C) Microsoft Corporation 1996-2001. All
rights
>reserved.

>Computer Usage Disclaimer

>All activity may be monitored. System use indicates
>consent to monitoring. Information may be given to law
>enforcement.
>sftp> ls

>sftp> quit

>--END

>As you can see the results of all sftp commands are not
>correctly output...  I have tried assigning certain
lines
>to an array using a regexp to test which lines I wish to
>capture and I get funky results...  Could this be caused
>by the fact that FTP uses a control port (for commands)
>and a data port (for data) and somehow the data info
gets
>lost in the objPipe object????

>Any help greatly appreciated... trying to figure this
one
>out and could really use your help!!!

>Cheers,
>David
>.



Tue, 18 Jan 2005 07:29:25 GMT  
 Using Scripting.Shell Exec command to capture the results of a SFTP ls command
asked and answered in ...scripting.wsh

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Tue, 18 Jan 2005 13:41:04 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problems with Wscript.Wshell Exec command handling of SFTP stdout output

2. Capture results from Shell command

3. Capture result/output from 'run'-command

4. capturing a shell commands output

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

6. API to capture result from DOS command ?

7. Capture text results from command line

8. Launching an exec from a client script using shell

9. Capturing Output from shell command to VB

10. Capture all shell command output?

11. Using the shell commands

12. Running DOS Shell in hidden window, or using vb command instead

 

 
Powered by phpBB® Forum Software