Printing date/time in the output
vinay · Mon Aug 23, 2010 1:49 pm
I want to print the date & time in the output file. I tried various methods. I could get a working solution, but can somebody suggest me a better alternative?
These are the things I have tried:
1.
Here lnk is a writable link to a text file.
This just prints the output of the system command to the link.
2. Then I tried to write to the file using shell redirections.
This really works...
But only if the file is not open! i.e. if the file is opened by some link, then this wont work.
So the only working solution I could find is:
Thanks and regards
VInay
These are the things I have tried:
1.
Code:
write(lnk,system ("sh","date"));
Here lnk is a writable link to a text file.
This just prints the output of the system command to the link.
2. Then I tried to write to the file using shell redirections.
Code:
write(lnk,system ("sh","date > a"));
OR
write(lnk,system ("sh","date >> a"));
OR
write(lnk,system ("sh","date >> a"));
This really works...
But only if the file is not open! i.e. if the file is opened by some link, then this wont work.
So the only working solution I could find is:
Code:
link lnk=":a file.txt" // Note the :a part. The link should be appendable, not just writable.
open(lnk);
do_your_process;
close(lnk);
write(lnk,system ("sh","date >> a")); // Note the >> redirection. If you put just one > then it will erase the whole
// file and just put the date.
open(lnk);
do_remaining_proces;
close(lnk);
open(lnk);
do_your_process;
close(lnk);
write(lnk,system ("sh","date >> a")); // Note the >> redirection. If you put just one > then it will erase the whole
// file and just put the date.
open(lnk);
do_remaining_proces;
close(lnk);
Thanks and regards
VInay