How do I read from, and write to, a bash pipe in C++?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sean Pedersen
    New Member
    • Dec 2010
    • 30

    #1

    How do I read from, and write to, a bash pipe in C++?

    Is it always characters, or can it be data?
    I'd also like to know when my program is being run directly, then it will behave differently.
    A great example of the input behavior desired is demonstrated through use of nano. Here's what I'm looking for:
    Code:
    int main(int argc, char * argv) {
        int len = 0;
        int buffer[] = new int[1024];
        while (!timeout() && len < 1024)
            len += getPipe(buffer, len, 1024-len);
        if (len == 0) doNoPipe();
    }
    ...where timeout(), getPipe(), and doNoPipe() are my functions.
Working...