external filter

Q&A's, tips, howto's
Locked
bairui
Posts: 64
Joined: Sun May 06, 2012 2:04 am
Location: China
Contact:

external filter

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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: external filter

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

bairui
Posts: 64
Joined: Sun May 06, 2012 2:04 am
Location: China
Contact:

Re: external filter

Post by bairui »

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

Locked