Differences in piping an executable and "exec ... >@xxx 2>@xxx"

From: Martin Lemburg (martin.lemburg.ugs_at_gmx.net)
Date: 09/26/04

  • Next message: Barry Kauler: "Re: Compiling Abacus spreadsheet"
    Date: 26 Sep 2004 04:50:41 -0700
    
    

    Hello,

    following situation - we have an executable (C main, F90 dll) from a
    supplier and this executable delievers text at stdout via "printf". We
    started this executable via "open |..." and at the end of the
    execution, after exit we received not bit of the text printed to
    stdout! Even introducing "fflush(stdout)" didn't help!
    We started the executable simply with exec and got again not a char of
    the text printed via printf to stdout.

    So we built an own little executable (evaluating a tcl script using
    "puts") using "printf" to print text from C to stdout, flushing the
    used channels ("fflush(stdout)") and communicated via pipe ("open
    |..."). At the end of the execution we missed all the printf results.
    All texts printed from tcl via "puts" were piped correctly to the
    calling application.

    Now we built the same little executable using "cout" instead of
    "printf". The results of "cout" were piped to the calling application,
    but seemed to be asynchronous to the "puts" used in the evaluated tcl
    script. Even using "cout.flush()" didn't stop the asynchronous thing.

    At last we started the executables via "exec" and using the
    pipe-capabilities into files open by tcl for stdout and stderr ("exec
    ... >@file001 2>@file002"). We got all outputs ("printf"'s, "cout"'s
    and "puts"') and we got them in the sequence we expected to get them!

    What is going wrong and where are the differences between "open |..."
    and "exec ... >@file001 2>@file002", belonging to the treatment of
    "prinft", "cout" and "puts" in a "piped" application?

    Thanks for any answer, or comment!

    Best regards,

    Martin Lemburg
    Unigraphics Solutions GmbH - UGS the PLM Company


  • Next message: Barry Kauler: "Re: Compiling Abacus spreadsheet"

    Relevant Pages

    • Re: Question about execution of threads and parent/child processes
      ... by both threads/processes dumping to stdout/stderr on your controlling ... > concerned that my first attempt at writing multi-threaded apps wasn't ... I don't think that the execution is happening in ... > child/thread1 stuff is printed to stdout first, ...
      (comp.unix.programmer)
    • Re: Question on call system
      ... resume execution only when the the script has finished execution? ... script mainly launches some executables, ... If stdout is buffered, I am not sure about how the results come out. ...
      (comp.lang.fortran)
    • Re: How can I send data through stdout from Tcl/Expect?
      ... another script, after execution. ... stdout is the default, so you can even ommit that: ... set expect input logging to off ...
      (comp.lang.tcl)
    • How can I send data through stdout from Tcl/Expect?
      ... I'm trying to send some data out via stdout from expect to pipe into ... another script, after execution. ...
      (comp.lang.tcl)
    • Re: EXEC and Windows XP
      ...   I'd say I'm pretty much a "noob" with tcl, but in reality, I'm very ... noob, ... to indicate routine execution). ...
      (comp.lang.tcl)