Hi,
I require to send an output from a unix command such as date, and store it into a file. The problem i have is that i cannot get the output from date into a char array.
Can anyone help me on this ..
Thankyou
Printable View
Hi,
I require to send an output from a unix command such as date, and store it into a file. The problem i have is that i cannot get the output from date into a char array.
Can anyone help me on this ..
Thankyou
Now read the output of date as if it were a fileCode:FILE *fp = popen( "date", "r" );
Not sure if this is the best method but it works for me :
Hope this helps.Code:#include <stdio.h>
int main(void)
{
FILE *filepointer = popen("date", "r");
char output[30];
while(fgets(output,sizeof(output),filepointer));
printf("Today is - %s", output);
pclose(filepointer);
return 0;
}
Stan
*edit sorry didnt see salem had already replied to this, I seem to experience quite a bit of lag on this board as it took me ages to get my message posted.
If you don't need a program for itCode:%ls -a > file.txt