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
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" );
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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