system call

I have a cgi script which is called after certain time interval, which has this:

system ("ls -l /tmp/cgic* | grep -v \"cgicsave.env\" |  awk '{print $5}'");

During the execution of this script,the output is 0 sometimes. But due to this the system call is not working at all and doesnt o/p anything only last value.

The output is zero? It really may have been; your script may be catching the file when it's been created, but before it's been written to.

As for only outputting the last value, I thought that was the whole point of you using {print $5}?

For example my o/p is :

86016
147456
208896
270336
.......
.......
.......
.......
.......
6733824
6795264
6856704
6918144
6979584
7041024
7098368
7127040
7143723
7143723
7143723

So, by "last value" I mean "7143723"

I have tried running *.cgi in the same folder, it works fine. But, as my Ajax reads the o/p, there is no data except this LAST VALUE.

---------- Post updated at 01:05 PM ---------- Previous update was at 12:47 PM ----------

If I re-frame my question. If the system call returns 0 or error, how to make it still work so that it o/ps the other values
for example;
I have:
for(i=0;i<100;i++)
system("cmd");

If for i=5 , the system call failed, then i want it to still work for other iterations of i.