By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,773 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

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

Sean Pedersen
P: 30
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:
Expand|Select|Wrap|Line Numbers
  1. int main(int argc, char * argv) {
  2.     int len = 0;
  3.     int buffer[] = new int[1024];
  4.     while (!timeout() && len < 1024)
  5.         len += getPipe(buffer, len, 1024-len);
  6.     if (len == 0) doNoPipe();
  7. }
...where timeout(), getPipe(), and doNoPipe() are my functions.
Dec 3 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.