To answer your questions:
1.) The command system returns the errorcode of the shell command,
where 0 means that no error occured. So
Code:
write(lnk,system ("sh","date"));
will only write a 0 to the link.
2.) By construction
links in Singular bhave very rigid. Once you open
an ascii-file by a link command, you can not acess it simultaneously by
>.
Since you only want to write the data to an ASCII file, you have two possibilities.
Either, you don't use
link but access the file simply by its filename
with preceeding > (to open) and >> (to append):
Code:
string lnkname = "file.dat";
write(">"+lnkname,"123"); // creates and write to file.date
write(">>"+lnkname,"hello"); // appends to the file
int errcode = system("sh","date >> " + lnkname); // append the date to file.dat
write(">>"+lnkname,"the end");
read(lnkname); // returns the whole file as a string
OR
work constantly work with
link but to get the date as a string,
you have to write it to a file, then read this file into a string,
and finally remove the file to clean the filesystem.
Here is proc which does the job:
Code:
proc timestamp()
{
// returns the date as a string
int errcode;
string fnm = "/tmp/date"+string(system("pid"))+".sig"; // create unique name
errcode = system("sh","date > "+fnm);
string date = read(fnm);
date[size(date)]=""; // remove endining newline
errcode = system("sh","rm -f "+fnm); // remove the date-file
return(date);
}
> timestamp();
Mi 25. Aug 15:21:10 CEST 2010
Then you can proceed as expceted:
Code:
link lnk=":a file.txt"; // Note the :a part. The link is appendabble not just writable.
open(lnk);
// do_your_process;
write(lnk,timestamp()); // write the date to the file
// do_remaining_proces;
close(lnk);