Issues with $system task

Hi,

I am trying to use $system task to do some grep operations on run log file. So when I run the test, everything gets dumped in the run log. At the end of the test, I want to grep the run log for some errors, e.g errors from some vendor models. My code is as below, I am using mentor simulator version: 10.7c_2_64.
The issue I see is that sometimes the grep works fine but sometime it does not. Even though the text ‘ERROR:’ is in the log, I will see model_err.txt has 0 in it. This causes no error to flag even though there is modeling error.
Also I am 100% sure that the grepping happens after the text ‘ERROR:’ is in the log. There is a 19us gap between the error and the error checking.
Please let me know if any insights.

      int fp, model_err;
      $system("grep -c 'ERROR:' run.log > model_err.txt");       ----- > prints the number of times 'ERROR:' is in the log
      fp = $fopen("model_err.txt","r");
      $fscanf(fp, "%d", model_err);
      $fclose(fp);
      if(model_err) `uvm_error("MODEL_ERR", "Error from vendor model")

Thanks.

In reply to poojanm2002:

Most likely this because of the way your tool streams file I/O for better performance. It’s possible that the error message has not been written out to the file at the time the $system task executes. You could try using the $fflush system task before calling $system.

There might be other ways of controlling how your tool flushes output. Please check your tools user manual or contact your vendor directly for support. This Mentor sponsored public forum is not for discussing tool specific issues.

In reply to dave_59:

Thanks Dave. I tried $fflush, it didn’t help. So I added some delay before I parse the log file and that worked.