[erlang-questions] Calling halt() only after I/O has completed.
Wed Apr 30 06:15:47 CEST 2008
I have small escript that reads a bunch of files, scans them for data,
and prints the matches to stdout ('standard_io', to be precise, going
to the 'user' process under the hood). If there were any matches,
then we have an error condition and the escript needs to return a
status of 1 to the shell.
If there are only a few matches, things work. If there are many
matches, then the main process calls halt(1) while the I/O process is
still sending the text to the terminal and the output gets truncated.
The only way I have found to work around this is to insert a delay
scaled by the number of records (100 ms seems to work). Calling
to synchronously close the port and flush the output doesn't work.
The top-level process just hangs.
What's the best solution for guaranteeing that all the data gets
printed before the program exits? This is with ERTS 5.5.4 on Linux.
More information about the erlang-questions