Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Go to solution
Highlighted
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
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.