newLISP Fan Club

Forum => newLISP in the real world => Topic started by: bairui on January 29, 2013, 08:19:25 PM

Title: external filter
Post by: bairui on January 29, 2013, 08:19:25 PM
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.
Title: Re: external filter
Post by: Lutz on January 30, 2013, 07:22:03 AM
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.
Title: Re: external filter
Post by: bairui on January 30, 2013, 07:09:03 PM
Thanks, Lutz. I'll play with those variations.