Solved

Piping Data from/to Other Program in UNIX

Posted on 1998-01-11
2
214 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

895 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

15 Experts available now in Live!

Get 1:1 Help Now