On Sat, Jan 25, 2025 at 8:56 AM Lindsay Lawrence <
lawrence.lindsayj...@gmail.com> wrote:

> Is there a straightforward way from PicoLisp, when executing an external
> process, to get stderr on a separate channel?
> I'd like to do something like (pipe) where I can connect stdin and stdout,
> but have an additional channel for the child's stderr
>
> After a bit of hacking, I've come up with the code below:

It uses pipe, redirects stderr of the Exe to a file and returns a list with
the stdout lines in the car and stderr in the cadr

I'm pretty happy with it :)

/Lindsay

(de runExe (Cmds . Exe)
   (use (LOut LErr)
      (let (ErrFile (tmp "exerr." (rand)))
         (finally (call "rm" ErrFile)
            (pipe
               (err ErrFile (out Exe (mapc prinl Cmds)))
               (setq LOut (make (while (line T) (link @)))) )
            (in ErrFile
               (setq LErr (make (while (line T) (link @)))) ) ) )
      (list LOut LErr) ) )


which works something like   this (note the error in the last command sent)

: (mapc '((X) (mapc println X))
    (runExe '(".mode quote"
              "select strftime('%s', 'now'), date('now');"
              "select date();"
              "select time();"
              "select datetim();"
              ".exit")
        sqlite3 "file:mdb?mode=memory" ))
"'1737836168','2025-01-25'"
"'2025-01-25'"
"'20:16:08'"
"Error: near line 5: no such function: datetim"
-> "Error: near line 5: no such function: datetim"

Reply via email to