Question : RedirectStandardOutput Not getting all the output

Hello, I'm trying to write a simple VB.net app that simply does this:

1. Click a button and it executes an ftp session using standard Windows FTP
2. Captures ALL the output
3. Write it to a text box.

Right now, it runs fine, but it doesn't capture all the output.

Here is the FTP session manually:
BEGIN--------------
C:\PROGRA~1\mydir>ftp -s:FTP.txt 123.123.123.123
Connected to 123.123.123.123
220 Mark III FTP server (Version 1.7 Tue Mar 14 10:10:00 GMT 2000) ready.
User (123.123.123.123:(none)):
331 Password required for USER123

230 User logged in, proceed.
ftp> dir
200 PORT command successful.
150 Data connection open for transfer of file EF123657.
Type  Name
dir   send
dir   receive
226 Closing data connection. Requested file action successful.
ftp: 54 bytes received in 0.00Seconds 54000.00Kbytes/sec.
ftp> cd /send
250 "send" is current directory.
ftp> quit
221 Goodbye.
END---------------

Now when I run my app, I get this:
BEGIN--------------------
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Program Files\mydir>ftp -s:C:\PROGRA~1\mydir\FTP.txt 123.123.123.123
User (123.123.123.123:(none)): Type  Name

dir   send

dir   receive

dir
cd /send
quit

C:\Program Files\mydir>exit
END--------------------

Please see code below. What can I do to capture everything?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
Imports System.IO

Public Class Form1

    Dim strResults As String = ""
    Dim intResult As Integer
    Dim strIP As String = "123.123.123.123"
    Dim strOutBox = "C:\PROGRA~1\mydir"
    Dim strFtpArgs = "C:\PROGRA~1\mydir\FTP.txt"
    Delegate Sub SetTextCallback(ByVal [text] As String)



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim intFileCount As Integer

        strResults = ""
        TextBox1.Text = ""


        'Check to see if there is anything to process
        intFileCount = System.IO.Directory.GetFiles(strOutBox).Length()

        If intFileCount <= 0 Then
            strResults = strResults & "There are no files to process." & vbCrLf
            TextBox1.Text = strResults
            Exit Sub
        Else
            Directory.SetCurrentDirectory(strOutBox)

            intResult = MsgBox("Are you sure you want to send to outbound files?", MsgBoxStyle.OkCancel)

            If intResult <> 1 Then
                Exit Sub
            End If
        End If



        Dim CMD As New Threading.Thread(AddressOf GETCMD)
        CMD.Start()
    End Sub


    Private Sub GETCMD()
        Dim CMDprocess As New Process
        Dim StartInfo As New System.Diagnostics.ProcessStartInfo


        StartInfo.FileName = "cmd"
        StartInfo.RedirectStandardInput = True
        StartInfo.RedirectStandardOutput = True
        StartInfo.UseShellExecute = False
        StartInfo.CreateNoWindow = True
        CMDprocess.StartInfo = StartInfo
        CMDprocess.Start()

        Dim SR As System.IO.StreamReader = CMDprocess.StandardOutput
        Dim SW As System.IO.StreamWriter = CMDprocess.StandardInput

        SW.WriteLine("ftp -s:" & strFtpArgs & " " & strIP)
        SW.WriteLine("exit")
        strResults = strResults & SR.ReadToEnd 'returns results of the command window

        Me.SetText(strResults)
        SW.Close()
        SR.Close()




    End Sub

    Private Sub SetText(ByVal [text] As String)

        If Me.TextBox1.InvokeRequired Then
            Dim d As New SetTextCallback(AddressOf SetText)
            Me.Invoke(d, New Object() {[text]})
        Else
            Me.TextBox1.Text = [text]
        End If
    End Sub

End Class

Answer : RedirectStandardOutput Not getting all the output

You do not "need" a trust to use ADMT however trusts can make migration alot easier so are recomended by most for that reason.
Random Solutions  
 
programming4us programming4us