By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

Could not get the standardoutput from the process simultaneously when the process is executing.

P: n/a
I am running an executable from my aspx page with the click of a
button. A date is passed as an argument. I am able to get the
standardoutput from the Process(Exe) into the label of my page after
the process has completed executing. My problem is I need to get the
output in the label simultaneously when the EXE is running, not after
it has completed executing. Just like when I run the Exe in the cmd
prompt. In my code I am opening two threads for standardoutput and
StandardError. All the standardoutput is being buffered in a
stringbuilder and then being displayed in the label. Is there any
command that I can display the standard ouput in a label after reading
a line from the string builder? Is this the correct way to approach?
Any help is appreciated. Below is my code.

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

Dim dt As Date
program.StartInfo.FileName = "Stage.exe"
program.StartInfo.Arguments = dt
program.StartInfo.WindowStyle = ProcessWindowStyle.hidden
program.StartInfo.UseShellExecute = False
program.StartInfo.RedirectStandardInput = True
program.StartInfo.RedirectStandardOutput = True
program.StartInfo.RedirectStandardError = True
program.Start()
srop = program.StandardOutput
sin = program.StandardInput
Dim oOutputThread As Thread = New Thread(AddressOf
ReadStdOut)
Dim oErrorThread As Thread = New Thread(AddressOf
ReadStdError)
With oOutputThread
.Name = "StandardOutput"
.Priority = ThreadPriority.Highest
.Start()
.Join()
End With

With oErrorThread
.Name = "StandardError"
.Priority = ThreadPriority.Normal
.Start()
.Join()
End With

End Sub

Private Sub ReadStdOut()
srop = program.StandardOutput
sin = program.StandardInput
Dim sb As New System.Text.StringBuilder("")

Dim input As String = srop.Read
Do Until input = -1
If input = 13 Then
sb.Append("<br>")
End If
sb.Append(ChrW(input))
input = srop.Read
Loop
Label1.Text += sb.ToString
End Sub

Private Sub ReadStdError()

Dim str As System.IO.StreamReader = program.StandardError
Dim sb As New System.Text.StringBuilder("")
Dim input As Integer = str.Read
Do Until input = -1
If input = 13 Then
sb.Append("<br>")
End If
sb.Append(ChrW(input))
input = str.Read
Loop
Label1.Text += sb.ToString
End Sub

Thanks,
Atluri.

Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.