vc++6.0: capture cerr

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike - EMAIL IGNORED

    vc++6.0: capture cerr

    I have a VC++6.0 program than calls library functions
    that write to cerr. I would like to capture this output
    in the calling program. Would you please let me know
    how I could to this? If I should ask on another group,
    please let me know.
    Thanks in advance,
    Mike.
  • WW

    #2
    Re: vc++6.0: capture cerr

    Mike - EMAIL IGNORED wrote:[color=blue]
    > I have a VC++6.0 program than calls library functions
    > that write to cerr. I would like to capture this output
    > in the calling program. Would you please let me know
    > how I could to this? If I should ask on another group,
    > please let me know.[/color]

    You need to. A Microsoft one. Or a POSIX one - if MS really does implement
    POSIX as they say the do. The Standard C++ has no support for this. I mean
    you can redirect cerr to file (well, not on all MS OSes) and then read that
    file, but I think you would rather want something like a pipe. And pipes
    are not in standard C++.

    --
    WW aka Attila


    Comment

    • Ryan Winter

      #3
      Re: vc++6.0: capture cerr

      Mike - EMAIL IGNORED wrote:[color=blue]
      > I have a VC++6.0 program than calls library functions
      > that write to cerr. I would like to capture this output
      > in the calling program. Would you please let me know
      > how I could to this? If I should ask on another group,
      > please let me know.[/color]

      Take a look at this page. It describes (in a round about way) how to
      reassign standard streams to whever you would like.



      Comment

      • Dietmar Kuehl

        #4
        Re: vc++6.0: capture cerr

        "WW" <wolof@freemail .hu> wrote:[color=blue]
        > Mike - EMAIL IGNORED wrote:[color=green]
        > > I have a VC++6.0 program than calls library functions
        > > that write to cerr. I would like to capture this output
        > > in the calling program. Would you please let me know
        > > how I could to this? If I should ask on another group,
        > > please let me know.[/color]
        >
        > You need to. A Microsoft one. Or a POSIX one - if MS really does implement
        > POSIX as they say the do. The Standard C++ has no support for this. I mean
        > you can redirect cerr to file (well, not on all MS OSes) and then read that
        > file, but I think you would rather want something like a pipe. And pipes
        > are not in standard C++.[/color]

        If the library really writes to 'std::cerr' rather than writing to the
        standard error stream using eg. 'fprintf(stderr , ...)' or 'write(2, ...)',
        there is a perfectly portable C++ solution to the problem: it is possible
        install a new stream buffer into 'std::cerr' to which all characters written
        to 'std::cerr' are sent:

        std::ostringstr eam serr;
        std::streambuf* cerr_sbuf = std::cerr.rdbuf ();
        std::cerr.rdbuf (serr.rdbuf());
        // now everything written to 'std::cerr' is captured by serr
        cerr.rdbuf(cerr _sbuf); // restore original stream buffer to avoid
        // references to deleted objects
        --
        <mailto:dietmar _kuehl@yahoo.co m> <http://www.dietmar-kuehl.de/>
        Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.co m/>

        Comment

        • Attila Feher

          #5
          Re: vc++6.0: capture cerr

          Dietmar Kuehl wrote:[color=blue]
          > "WW" <wolof@freemail .hu> wrote:[color=green]
          >> Mike - EMAIL IGNORED wrote:[color=darkred]
          >>> I have a VC++6.0 program than calls library functions
          >>> that write to cerr. I would like to capture this output
          >>> in the calling program. Would you please let me know
          >>> how I could to this? If I should ask on another group,
          >>> please let me know.[/color]
          >>
          >> You need to. A Microsoft one. Or a POSIX one - if MS really does
          >> implement POSIX as they say the do. The Standard C++ has no support
          >> for this. I mean you can redirect cerr to file (well, not on all MS
          >> OSes) and then read that file, but I think you would rather want
          >> something like a pipe. And pipes are not in standard C++.[/color]
          >
          > If the library really writes to 'std::cerr' rather than writing to the
          > standard error stream using eg. 'fprintf(stderr , ...)' or 'write(2,
          > ...)', there is a perfectly portable C++ solution to the problem: it
          > is possible install a new stream buffer into 'std::cerr' to which all
          > characters written to 'std::cerr' are sent:
          >
          > std::ostringstr eam serr;
          > std::streambuf* cerr_sbuf = std::cerr.rdbuf ();
          > std::cerr.rdbuf (serr.rdbuf());
          > // now everything written to 'std::cerr' is captured by serr
          > cerr.rdbuf(cerr _sbuf); // restore original stream buffer to avoid
          > // references to deleted objects[/color]

          "I would like to capture this output in the calling program."

          Do you know any standard IPC mechanism in C++? Just because you say that it
          can be done using standard C++...

          --
          Attila aka WW


          Comment

          • Buster

            #6
            Re: vc++6.0: capture cerr


            "Attila Feher" <attila.feher@l mf.ericsson.se> wrote[color=blue]
            > Dietmar Kuehl wrote:[color=green]
            > > "WW" <wolof@freemail .hu> wrote:[color=darkred]
            > >> Mike - EMAIL IGNORED wrote:
            > >>> I have a VC++6.0 program than calls library functions
            > >>> that write to cerr. I would like to capture this output
            > >>> in the calling program. Would you please let me know
            > >>> how I could to this? If I should ask on another group,
            > >>> please let me know.[/color][/color][/color]

            [...]
            [color=blue]
            > "I would like to capture this output in the calling program."
            >
            > Do you know any standard IPC mechanism in C++? Just because you say that it
            > can be done using standard C++...[/color]

            Read it again. The calling program "calls library functions";
            there is no mention, explicit or otherwise, of multiple processes.

            Regards,
            Buster.


            Comment

            • WW

              #7
              Re: vc++6.0: capture cerr

              Buster wrote:
              [SNIP][color=blue]
              > Read it again. The calling program "calls library functions";
              > there is no mention, explicit or otherwise, of multiple processes.[/color]

              You are right. My English is even worse than I thought. Thanx for the
              clarification.

              --
              WW aka Attila


              Comment

              Working...