Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

Piping Data from/to Other Program in UNIX

Hello,
I'm re-teaching my self C and am trying to do something that I have seen in PERL but doesn't appear to work the same in C. In PERL you can open a pipe to another program using the regular file open command. You do this by using the name of the program you want to pipe as the file name in the open command with the pipe character either before or after the program name depending on weather you want to pipe data in or out. Ounce its open you can read or write to it the same way you would to a disk file.

Now, I know that C uses the same concept of streams and piping is built into the UNIX environment so I'm pretty sure you can do it but I suspect the method is a little different then opening a disk file in C. Can anybody tell me how?

Thanks
0
grobin
Asked:
grobin
1 Solution
 
julio011597Commented:
Yes, you are quite near to it.

The rilevant functions are popen() and pclose() (include <stdio.h>).

popen() returns a pointer to FILE, so you work with this pointer the same way you would with any "regular" file.

Try man popen for further details.

Regards
0
 
grobinAuthor Commented:
yup, that did it. Thanks a bunch


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now