getting stderr from an app launched via execv

This is a discussion on getting stderr from an app launched via execv within the Linux Programming forums, part of the Platform Specific Boards category; I have an application that calls another app and reads its output from stdout and also traps output to stderr ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    1

    getting stderr from an app launched via execv

    I have an application that calls another app and reads its output from stdout and also traps output to stderr too.

    It originally used popen and trapped stderr by passing "2>out.err" as the last parameter and it worked fine.
    But I also needed to be able to send a SIGINT to the program and couldn't using the popen architecture.

    So I've changed my code to use fork / execv and now the last parm "2>out.err" is being passed to the app and not treated the same was as it was with popen.

    So my question is, how can I trap prints to stderr from the app that I launched using execv?

    Thanks
    Kevin

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    In the child process, just before you exec...

    - open "out.err" for writing
    - close descriptor 2
    - Call dup with the descriptor from step 1
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 07:11 AM
  2. fprintf to stderr crash programs
    By jlai in forum Windows Programming
    Replies: 2
    Last Post: 04-12-2005, 08:51 AM
  3. best program to start
    By gooddevil in forum Networking/Device Communication
    Replies: 4
    Last Post: 05-28-2004, 05:56 PM
  4. Need help migrating console app to windows app
    By DelphiGuy in forum C++ Programming
    Replies: 1
    Last Post: 03-14-2004, 06:05 PM
  5. pasword app
    By GanglyLamb in forum C Programming
    Replies: 2
    Last Post: 06-07-2003, 10:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21