Is there a way to ensure copy-port is unbuffered? I am seeing processes dying due to error without any output through copy-port, output comes all in one chunk when the process finishes successfully.
I am actually looking at the code of copy-port and it doesn’t seem like its buffering anything which is all the more strange. :confused:
@pocmatos Many ports are buffered by default, and it looks like copy-port never calls flush-output. One option is to set the buffer mode of the output ports to unbuffered and use the existing copy-port; another is to make your own copy-port that calls flush-output. (Seems like it would be useful to add a #:flush? option to copy-port too.)
@ryanc I have defined my own copy-port for now with flushing enabled. I will send a PR.
@jxxcarlson has joined the channel
Hi there! I am using the code below to append strings to a file: (define (save-string str)
(write (string-append str "\n") (open-output-file data-file #:exists 'append #:mode 'text))
) But here is what I get: one
two
three
"foo bar\n" where "foo bar\n" was added by save-string. What I want is a file that looks like
one
two
three
foo bar(with a new-line at the end)
@jxxcarlson You are getting that because you are using write.
Write behaves like that because cores instances need to able to be read back in.
Try for your case fprintf on the output-port and then don’t forget to close it.
or even better use with-output-to-file which automatically closes the port: