Results 1 to 4 of 4

Thread: Problem with ReadToEnd and output freeze

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    Problem with ReadToEnd and output freeze

    Hello, I'm trying to embed command prompt to my app. The output textbox is freezing when I run the program. Actually it isn't freezing, it's waiting exe to finish its work. I want to get lines immediately as it does in command prompt.

    vb.net Code:
    1. Private Sub CMDAutomate()
    2.  
    3.     Dim cmdProcess As New Process
    4.     Dim StartInfo As New System.Diagnostics.ProcessStartInfo
    5.     StartInfo.FileName = "anexecutable" 'starts cmd window
    6.     StartInfo.Arguments = "somearguments"
    7.     StartInfo.RedirectStandardInput = True
    8.     StartInfo.RedirectStandardOutput = True
    9.     StartInfo.UseShellExecute = False 'required to redirect
    10.     StartInfo.CreateNoWindow = True 'creates no cmd window
    11.     cmdProcess.StartInfo = StartInfo
    12.     cmdProcess.Start()
    13.  
    14.     Dim SR As System.IO.StreamReader = cmdProcess.StandardOutput
    15.     Dim SW As System.IO.StreamWriter = cmdProcess.StandardInput
    16.     SW.WriteLine(OutputTextBox.Text) 'the command you wish to run.....
    17.     SW.WriteLine("exit") 'exits command prompt window
    18.     Results = SR.ReadToEnd 'returns results of the command window
    19.     SW.Close()
    20.     SR.Close()
    21.     'invokes Finished delegate, which updates textbox with the results text
    22.     Invoke(Finished)
    23.  
    24. End Sub

    By the way, (I don't know where to ask) how can I wrap my codes in this site with vb.net style?
    Last edited by nikel; May 21st, 2015 at 05:33 AM. Reason: I edited highlight

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width