Page 1 of 1

external filter

Posted: Wed Jan 30, 2013 4:19 am
by bairui
What is a more idiomatic way to do this? :

Code: Select all

(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.

Re: external filter

Posted: Wed Jan 30, 2013 3:22 pm
by Lutz
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:

Code: Select all

(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.

Re: external filter

Posted: Thu Jan 31, 2013 3:09 am
by bairui
Thanks, Lutz. I'll play with those variations.