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

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 properly...

Here is the code:

Dim strStdOutLine, i
Dim objShell, objPipe, objRE

Set objRE = New RegExp
Set objShell = CreateObject("Wscript.Shell")

objRE.Pattern = "^DIRECTORY\s$"

Set objPipe = objShell.Exec("%COMSPEC% /C ""echo ls |

i = 1
While Not objPipe.StdOut.AtEndOfStream
  strStdOutLine = objPipe.StdOut.ReadLine()
  If objRE.Test(strStdOutLine) Then
    If (i mod 2) = 1 Then  ' Only true if odd so to
contrast the problem lines--alternate one good one bad.
      Wscript.Echo strStdOutLine, "Oops"
    Else
      Wscript.Echo strStdOutLine
    End If
    i = i + 1
  Else
    Wscript.Echo strStdOutLine, "<-- not affected!?"
  End If
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 <-- not affected!?
 <-- not affected!?
All activity may be monitored. System use indicates
consent to monitoring. Information may be given to law
enforcement. <-- not affected!?
sftp> ls  <-- not affected!?
 Oops
.
 OopsTORY_A
DIRECTORY_B
 OopsTORY_C
DIRECTORY_D

--END

As you can see the results of all sftp commands are not
correctly output...  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 as
it cannot handle SFTP LF instead of CRLF?  If so, any
sugestions on how to correct this?

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

Cheers,
David

  output.txt
< 1K Download


Tue, 18 Jan 2005 08:13:48 GMT  
 Problems with Wscript.Wshell Exec command handling of SFTP stdout output
Here's the WshShell.Exec template code I use to ensure that all output is captured and the Exec'd process doesn't block on a full stdout buffer...

sCmd = "some command string"

set shell = createobject("wscript.shell")
Set d = CreateObject("Scripting.Dictionary")

set wsx = shell.exec(sCmd)
set wsxOut = wsx.stdout

do: wscript.sleep 10
  do until wsxOut.atendofstream
    d(d.count) = wsxOut.readline
  loop
loop until wsx.status <> 0 and wsxOut.atendofstream

arLines = d.items()

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



Tue, 18 Jan 2005 13:03:10 GMT  
 
 [ 2 post ] 

 Relevant Pages 

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

2. Exec command & StdOut problems

3. wscript.shell.exec STDOUT / ReadAll size limit?

4. ASP wscript/wshell problems with IWAM_USER

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

6. stdout problems (catching output from java aps)

7. Exec grabbign stdout

8. passing Exec.StdOut back "live"?

9. q: asynch piping of WshShell.Exec.StdOut

10. q: asynch piping of WshShell.Exec.StdOut

11. Problems with console output handling

12. redmon swith output between Prompt for filename and Program Handles Output

 

 
Powered by phpBB® Forum Software