Operating System - Linux
1748287 Members
3366 Online
108761 Solutions
New Discussion

Re: C: How to pull in info from the system?

 
SOLVED
Go to solution
tony j. podrasky
Valued Contributor

C Programming Language: How To Pull In Information From The System?

Hello Everyone;

 

I want to run the <apm> command, from withing a C program, and get the program to receive the output - so that I can display it in an xsession (window) on my screen.

 

I've used the <system> call to tell the O/S what to do - but I don't know where to look to find out how to issue a system call and have the program receive the output.

 

Any ideas are appreciated.

 

regards,

tonyp

 

REMEMBER: Once you eliminate your #1 problem, #2 gets a promotion.
3 REPLIES 3
Dennis Handly
Acclaimed Contributor
Solution

Re: C: How to pull in info from the system?

The correct function is popen(3) with the "r" parm.  Or you could use pipe(2) with fork(2)/exec(2).

And example of the reverse popen(3) is here:

http://h30499.www3.hp.com/t5/Languages-and-Scripting/Facing-problem-with-popen-system-call-in-HP-UX/m-p/6566228#M47094

tony j. podrasky
Valued Contributor

Re: C: How to pull in info from the system?

Hello Dennis;

 

All I needed was the <popen> function.

 

Worked as expected.

 

Now I can re-write all the programs that I wrote that use [system abcdefg >> output] and then do an <open> of "output".

 

The link you left was a bonus!

 

Thank you for your help!

 

regards,

tonyp

REMEMBER: Once you eliminate your #1 problem, #2 gets a promotion.
Dennis Handly
Acclaimed Contributor

Re: C: How to pull in info from the system?

>Thank you for your help!

 

If the posts were helpful, please click on the kudos stars, both here and at the link.