Hi Tomas,

> is it possible in picolisp to create pipes from external programs,
> e.g. like in bash?  I.e. create a pipe, write to it on one end and
> read from it on the other end?  E.g. `base64 | wc -l`?

A one-stage pipe to another program can be called directly, as shown in
the example for 'pipe' (using 'tr') in the HTML documentation.

For longer pipes, the simplest way is to call 'sh' for that:

   : (in '("sh" "-c" "cat lib.l |base64 |wc -l")
      (read) )
   -> 145

or, more general,

   : (let File "lib.l"
      (in (list "sh" "-c" (pack "cat " File "|base64 |wc -l"))
         (read) ) )
   -> 145


Doing without the help of a shell is also possible, perhaps a lot more
efficient but a bit unintuitive:

   : (pipe
      (pipe (in "lib.l" (out '(base64) (echo)))
         (out '(wc "-l")
            (echo) ) )
      (read) )
-> 145



> Also, is it possible in the following code to suppress the two prompts
> 
> Encryption key:
> Again:
> 
> shown by bcrypt?  Maybe read the two lines in or redirect bcrypt
> stdout to /dev/null?

I don't have 'bcrypt' installed, but from the code I suspect that these
messages are sent to stderr. I see no easy way to suppress them (if
'bcrypt' has no "silent" option), except for redirecting stderr of the
whole picoLisp process.


Two notes on the 'bcrypt' function (just to be pedantic :-)

>    (unless (<= 8 (length (pipe (prin Salt) (line T))) 56)

This can simply be achieved by

     (unless (<= 8 (length Salt) 56)

as 'length' already returns the desired value.


>    (let (F (pipe (call 'mktemp)
>              (line T))

could be

>    (let F (in '(mktemp) (line T))

(Just for the records, but I'm sure you know that)

The same with:

>          (cons Salt (pipe (call 'base64 '-w 0 G) (line T)))

could be

>          (cons Salt (in (list 'base64 '-w 0 G) (line T)))

Doing without 'pipe' is more efficient, as an additional 'fork' is
avoided ('pipe' forks once, and 'call' forks again).

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]

Reply via email to