Storing the output of a Unix cmd in my C program

Hello experts,

How can I retrieve the output from a Unix command and use it as string variable in my C program?
For example, when I issue the command 'date' I get:
Tue Jun 11 09:54:16 EEST 2009

I do not want to redirect the output of the command to a file and then open the file from my C program and then read the string.

Is there any other way?

Thank you in advance,
G.

  1. Moved to programming
  2. instead of reading from an external program, why not use man strftime (POSIX)?

Use popen...it will give you a pointer to the output of date which can then be manipulated.

thank you guys... I can do just that!