Is there any way for me to run a system command such as date through my C program and pipe the output to a char *date so I can use it later? I’ve been trying to use the “system” command but doing system(“date”); immediately prints out the date output to stdout. I want to grab this data using system or exec within my program. Any suggestions would be appreciated…
Thanks!
Take a look at
popen(). You open aFILEpointer with it, like so:And then you can use
fread()orfscanf()to read fromfinto your buffer of choice.