external filter

Started by bairui, January 29, 2013, 08:19:25 PM

Previous topic - Next topic

bairui

What is a more idiomatic way to do this? :


(set 'tmp-file (open "/tmp/file" "write"))
(write tmp-file (join (map markup (parse pretext "n" 0)) "n"))
(close tmp-file)
(setf posttext (join (exec "fmt -68 /tmp/file") "n"))


It feels dirty to use a /tmp/file like that. Ideally I'd like to pipe a string through `/bin/fmt` capturing its STDOUT, all within newlisp.

Lutz

#1
You could have shortened your code by using write-file, but you seem to look for a solution without using an intermediary file.



The following uses STDIN on exec and would leave the result in a file posttest and no temporary file is required:



(exec "fmt -68 > posttext" (join (map markup (parse pretext "n" 0)) "n"))

Then you could (read-file "postttext") to bring the result into memory.



Ps: look also into process which can take two pipes at once.

bairui

#2
Thanks, Lutz. I'll play with those variations.