|
-
Feb 17th, 2017, 08:44 AM
#1
RedirectingStandardError is redirecting standard output also
Hey all,
I've create a console app that handles some pdf conversions for me. In this app I send some text to the console and if an error occurs, I send text to Console.Error...
VB.net Code:
'for console writes...
Console.WriteLine("Converting page " & pageNumber.ToString)
'for error writes...
Console.Error.WriteLine("An error occur during the pdf page conversion.")
I am then running the console app from a windForm app with this code...
VB.Net Code:
Private Function pdfToImg(pdfPath As String, destinationPath As String, pdfToImgAppPath As String) As String
Dim returnErrString As String = ""
Dim p As New Process
With p.StartInfo
.FileName = pdfToImgAppPath
.Arguments = String.Format("{0} {1}", pdfPath, destinationPath)
.RedirectStandardOutput = False
.RedirectStandardError = True
.UseShellExecute = False
End With
p.Start()
p.WaitForExit(30000)
If Not p.HasExited Then
p.Kill()
returnErrString = "An unknow error has occured in the pdf conversion. The process never ended."
Else
returnErrString = p.StandardError.ReadToEnd
End If
Return returnErrString
End Function
My intent is have the standard output go to the console, but redirect the error so I can display and log it, However when I set RedirectStandardError=True, it is redirecting all output including the standard output which I want to remain in the console window.
Has anyone seen this behavior before and know how to resolve it?
thanks
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Feb 17th, 2017, 09:01 AM
#2
Re: RedirectingStandardError is redirecting standard output also
I know that with binding it makes a difference in the order of the lines (setting DisplayMember and ValueMember before setting the datasource)... have you tried switching the Output and Error redirects? So that you set the error redirect first, then the standard redirect? Can't say I've ever seen this before but then usually when I'm redirecting, I want it all ... never tried splitting it.
Curious to see if that makes a difference or not, and whether you get it working.
-tg
-
Feb 17th, 2017, 09:09 AM
#3
Re: RedirectingStandardError is redirecting standard output also
have you tried switching the Output and Error redirects?
Doesn't seem to make a difference. Setting the error redirect stops the console from updating.
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Feb 17th, 2017, 01:47 PM
#4
Re: RedirectingStandardError is redirecting standard output also
FWIW WaitForExit should be called after ReadToEnd, according to MSDN
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|