I don't understand how to code Pipes

This is a discussion on I don't understand how to code Pipes within the C++ Programming forums, part of the General Programming Boards category; I'm having such a hard time. The concept is pretty easy, I want to pipe the stdout of one program ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    3

    I don't understand how to code Pipes

    I'm having such a hard time. The concept is pretty easy, I want to pipe the stdout of one program into the stdin of another program.

    This is setup from a 3rd program.

    To create a child process I'm using CreateProcess, but I don't really know where to go from there. Anything you guys can tell me to guide me in the right direction would help greatly.

    Thank you

  2. #2
    Registered User
    Join Date
    May 2007
    Posts
    147
    OS?

    If we knew the compiler it might help too.

    You say you want stdout applied to stdin - well, you can arrange that from the command line (as in system("oscommand here"); ).

    Pipes on the command line are constructed with | between them.

    command1 | command2

    For example.

    At which point, command1 does printf or cout >> to send material, command2 could use cin << to fetch it (or other C runtime functions).

    Did you prefer to open the pipe within the application? If you're in Unix, that's not as commonly done as the approach I'm identifying, and indeed, that's not stdout, it's some other 'channel' you're opening yourself, but it's similar work afterwards.

    In Unix/Linux, that was often done with popen. The command popen launches has it's stdin and stdout routed to the FILE handle popen returns to you. That application is written to write to cout and read from cin (or similar C runtime I/O like gets, printf, putc, whatever).

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    OS?

    ...

    Did you prefer to open the pipe within the application? If you're in Unix, that's not as commonly done as the approach I'm identifying, and indeed, that's not stdout, it's some other 'channel' you're opening yourself, but it's similar work afterwards.

    ...
    Windows, no doubt.
    To create a child process I'm using CreateProcess ...
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 08:34 AM
  2. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

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