Results 1 to 4 of 4

Thread: RedirectingStandardError is redirecting standard output also

  1. #1

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    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:
    1. 'for console writes...
    2. Console.WriteLine("Converting page " & pageNumber.ToString)
    3.  
    4. 'for error writes...
    5.  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:
    1. Private Function pdfToImg(pdfPath As String, destinationPath As String, pdfToImgAppPath As String) As String
    2.  
    3.         Dim returnErrString As String = ""
    4.          Dim p As New Process
    5.         With p.StartInfo
    6.             .FileName = pdfToImgAppPath
    7.             .Arguments = String.Format("{0} {1}", pdfPath, destinationPath)
    8.             .RedirectStandardOutput = False
    9.             .RedirectStandardError = True
    10.             .UseShellExecute = False
    11.         End With
    12.         p.Start()
    13.         p.WaitForExit(30000)
    14.  
    15.         If Not p.HasExited Then
    16.             p.Kill()
    17.             returnErrString = "An unknow error has occured in the pdf conversion. The process never ended."
    18.         Else
    19.             returnErrString = p.StandardError.ReadToEnd
    20.         End If
    21.         Return returnErrString
    22.  
    23.     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

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    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

  4. #4
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,190

    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
  •  



Click Here to Expand Forum to Full Width