Solved

Piping Data from/to Other Program in UNIX

Posted on 1998-01-11
2
213 Views
Last Modified: 2010-04-02
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
Comment
Question by:grobin
2 Comments
 
LVL 5

Accepted Solution

by:
julio011597 earned 50 total points
ID: 1256975
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
 

Author Comment

by:grobin
ID: 1256976
yup, that did it. Thanks a bunch


0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now