show cmd window output and redirect to message box

I would like to see the output on the cmd window that popsup and then display it in a message box.  Currently it just pops up a cmd window thats blank and when the script is done it shows the output in the message box.  

Dim NVDLink As New Process
        Dim strRDomain As String = ""
        If RadioButton2.Checked = True Then
            strRDomain = "sw"
        ElseIf RadioButton1.Checked = True Then
            strRDomain = "ss"
        End If

        If ComboBox1.Text = "" Then
            MessageBox.Show("You must enter a NVDLink to search for", "Enter NVDLink", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End If

        With NVDLink.StartInfo
            .CreateNoWindow = False
            .RedirectStandardOutput = True
            .RedirectStandardError = True
            .UseShellExecute = False
            .Arguments = "/c rsh toolsrv /scripts/nvdlink " & ComboBox1.Text & " " & strRDomain & " > c:\temp\nvdlink.txt"
            .FileName = "cmd.exe"
        End With
        Dim srNvdlink As New StreamReader("c:\temp\nvdlink.txt")
        Dim strNVD As String = ""
        While Not srNvdlink.EndOfStream()
            Dim line As String = srNvdlink.ReadLine

            If line <> "" Then

                If line <> "nothing returned" Then
                    strNVD += line & vbCrLf
                End If

            End If

        End While
        MessageBox.Show(strNVD, "NVDLink", MessageBoxButtons.OK, MessageBoxIcon.Information)

Who is Participating?
parnassoConnect With a Mentor Commented:
The problem is that if you want to do something with the output data, something like parsing, you need to redirect, and it means that the console output window will show nothing.

I can only foresee two alternatives:

1. You can use a Text control and add the lines to it. Put the control properties to show a black background and white text as a console.  

2. You can create another Console window and rewrite the output to it from the variable strNVD or the strNVD variable itself.

What I would do is to delete the output file redirection ( > c:\temp\nvdlink.txt)
and read the output stream to the end:

StreamReader theOutput = NVDLink.StandardOutput;
strNVD = theOutput.ReadToEnd();


I'm sorry about the syntax, byt in C# the thing works for me
I forgot the start

StreamReader theOutput = NVDLink.StandardOutput

Dim strNVD As String = ""
strNVD = theOutput.ReadToEnd()


Open in new window

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

chadmanvbAuthor Commented:
That does not seem to work.  I still see the cmd window popup, but dont see the output being displayed to the window.  
I am re-reading your post, and maybe I misunderstood you. You want both the windows cmd popup showing the results, and after that show the result output in a string to do whatever with it. Is that right?

In that case, I'm sorry to make you lose your time with my previous post.
Please let me know if at the end of the process the variable strNVD  is empty.

Your current application, is a windows form application or a console application?
chadmanvbAuthor Commented:
This is a form application.  My goal was to have the user just see the output on the cmd window while the script was running.  I was going to use this kind of like a progress bar, but it would let the user also see the output while they are waiting.  I do get the correct info on the strNVD.
chadmanvbAuthor Commented:
Thanks!  I thought about that, but just put a progress bar instead.  Thanks again for all of the help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.