Robert K. wrote:
On 03/03/2010 08:35 PM, Caleb C. wrote:
one with enough information to make that judgment.
Albert still did not disclose what the external program should do with
the temporary file […]
Thank you all, this task is behind me already.
If it interests you, then the external command I’m using is ‘dot’ (from
the graphviz package).
The command I’m using is something like this:
dot “%s” -Tgif -o “%s” -Tsvg -o “%s”
(I need three temporary files, in this example. ‘dot’ reads the first
file and writes images to the next two files.)
Smart guys would say that instead, on POSIX systems, I could write the
command as…
dot /dev/fd/10 -Tgif -o /dev/fd/11" -Tsvg -o /dev/fd/12
…but then I’d need to read simultaneously from fd/11 and fd/12 because
I’m not sure which is written first. But I need my program to work on
Windows too and I’m not sure it supports this “sophistication”.
Caleb C. wrote:
I’m not expert enough to be certain about this, but by doing this
you’ll be creating a tempfile race condition […]
I don’t care much about robustness because the command is run from an
interactive application by a single user and I’m using the files
immediately. There isn’t much a chance for a race condition.
Caleb C. wrote:
I think that if you create a temporary file with Tempfile, and then
DON’T CLOSE IT, you can safely pass the tempfile’s name to an external
command.
For some reason, the files aren’t always deleted (well, it seems they’re
never deleted). I don’t know why. At first I suspected ‘dot’ re-creates
the files, but when I do “ls -i” I see that the inodes haven’t changed.
But I can live with this bug. Maybe I could add some code to the
“destructor” of my class to explicitly delete these files. Does Ruby
support “destructors”?