pocmatos
2018-10-15 11:08:19

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.


pocmatos
2018-10-15 11:21:20

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:


ryanc
2018-10-15 13:11:49

@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.)


pocmatos
2018-10-15 13:14:03

@ryanc I have defined my own copy-port for now with flushing enabled. I will send a PR.


jxxcarlson
2018-10-16 05:32:37

@jxxcarlson has joined the channel


jxxcarlson
2018-10-16 05:36:36

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

jxxcarlson
2018-10-16 05:36:51

(with a new-line at the end)


pocmatos
2018-10-16 06:16:01

@jxxcarlson You are getting that because you are using write.



pocmatos
2018-10-16 06:16:25

Write behaves like that because cores instances need to able to be read back in.


pocmatos
2018-10-16 06:17:15

Try for your case fprintf on the output-port and then don’t forget to close it.


pocmatos
2018-10-16 06:17:52

or even better use with-output-to-file which automatically closes the port: