pipes

This is a discussion on pipes within the C Programming forums, part of the General Programming Boards category; Is there a way for me to do something like popen () but with two FILE*s, one read only, one ...

  1. #1
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946

    pipes

    Is there a way for me to do something like popen () but with two FILE*s, one read only, one write only, redirecting both the stdout and stdin of the command? Or one read-write FILE*, doesn't make a difference to me

    Thanks in advance
    hello, internet!

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    I'm not quite sure what you mean, but you can use the shell's redirection feature to do what it sounds like you want to do: myprog < inputfile > output file
    If you understand what you're doing, you're not learning anything.

  3. #3
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Yes, thats exactly what I want to do, except not from files on disk, but rather streams controlled by my program.
    hello, internet!

  4. #4
    Im a Capricorn vsriharsha's Avatar
    Join Date
    Feb 2002
    Posts
    192
    Try DUP/DUP2 calls if you are using Unix/Linux, if thats what you are looking for.
    Help everyone you can

  5. #5
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    hmm.... so, i could do something like this?

    1. make two pipes
    2. fork
    3. make one pipe go in each direction from child <-> parent
    4. dup2 stdout and stdin on the child to the pipes
    5. exec() the desired program on the child

    and then the stdin and stdout of the desired program would be accessable by the pipes in the parent?
    hello, internet!

  6. #6
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    Once you call exec then you will overwrite whatever you did to your child program. So setting up stdin and stdout and pipes would be useless after you call exec.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  7. #7
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    I had interpretted "File descriptors open in the calling process image remain open in the new process image, except for those for which the close-on-exec flag is set (see close(2) and fcntl(2)). Descriptors that remain open are unaffected by execve." to mean that whatever stdin and stdout are directed to before exec stay that way?

    if not, then how should i do what i want to?
    hello, internet!

  8. #8
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    My bad, you are right.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  9. #9
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Thanks for the help

    Unfortunately, I just realized that licensing issues of my project prevent using cygwin, and mingw doesnt have pipe() or fork() afaik.... =/

    fortunately Satan has a code example for me to work off of though =D

    http://msdn.microsoft.com/library/de...and_output.asp
    hello, internet!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pipes sometimes fail
    By EVOEx in forum Linux Programming
    Replies: 2
    Last Post: 05-02-2009, 02:47 PM
  2. Pipes
    By Martin Kovac in forum C Programming
    Replies: 1
    Last Post: 03-31-2009, 04:09 AM
  3. pipes in c
    By ajal1 in forum C Programming
    Replies: 6
    Last Post: 10-29-2005, 04:29 PM
  4. Need some help with pipes please.
    By carrja99 in forum C Programming
    Replies: 1
    Last Post: 05-05-2004, 05:13 PM
  5. Services and Pipes
    By nickname_changed in forum Windows Programming
    Replies: 0
    Last Post: 07-16-2003, 07:46 AM

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