Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: How to get a temporary file handle within mata?


From   Phil Schumm <[email protected]>
To   Statalist Statalist <[email protected]>
Subject   Re: st: How to get a temporary file handle within mata?
Date   Mon, 10 Mar 2014 13:07:37 -0500

On Mar 10, 2014, at 11:09 AM, Andrew Maurer <[email protected]> wrote:
> I am writing a mata function that writes to a file using fopen(), fwrite(), and fclose(). I run into issues if the function returns an error and aborts between fopen() and fclose(). The file stays open, can't be manually deleted, and the file handle can't be accessed to fclose() it, since the file handle was a local mata object.


You need to trap any potential errors (e.g., by using the underscore versions of the file I/O functions) and, in the case of an error, close the file(s) yourself.


-- Phil


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index