Hi Simon, if we take the classic ps aux | grep X

Obviously you can just input one function into the next like this: (println
(excmd~exe (excmd~script 'ps T 'aux) T 'grep 'bash))

Not so elegant, so I added this to cmd.l:

(de chain @
   (let Str (in (next) (till NIL T))
      (while (next)
         (setq Str (pipe (out @ (prin Str)) (till NIL T)))) ) )

So you can do like this: (println (excmd~chain '(ps aux) '(grep bash)))

But actually being able to do something like this might be more useful:

(println (excmd~chain
            '(ps aux)
            '((L) (pack L "hijacked with a bash^Jand another line with a
bash"))
            '(grep bash)
            '((L) (mapcar pack (split L "^J"))) ) )

So I updated the above function to look like this:

(de chain @
   (let Str (in (next) (till))
      (while
         (let? L (next)
            (setq Str
               (if (or (sym? L) (lst? (car L)))
                  (L Str)
                  (pipe (out L (prin (if (str? Str) Str (pack Str))))
(till)) ) ) ) )
      Str ) )

More to your likening?




On Thu, Apr 17, 2014 at 9:50 PM, Simon Luetzelschwab <simo...@gmail.com>wrote:

> Thanks for the response Mansur and Henrik - much appreciated.
>
> Mansur - Great, this looks much better!
>
> Henrik - I have been looking ath the articles on ProDevTips and some of
> the libs on bitbucket - very helpful as well.
>
> What I'm really trying to do is have an easy way to invoke arbitrary shell
> commands that may be piped, process the result in pico and maybe use that
> as the input for another command.
>
> I haven't found a generic example yet that doesn't specify the command
> specifically that allows arbitrary piping and still gives you access to
> intermediary results.
>
> Feel free to point me to any additional examples that go beyond calling
> one hardcoded command.
>
> Thanks again and I'm sure I'll be back with more questions!
>
> Best,
> Simon
>
>
> On Wed Apr 16 2014 at 10:02:09 PM, Henrik Sarvell <hsarv...@gmail.com>
> wrote:
>
>> Hi Simon, this is similar to stuff in my own system command helper
>> script, I use it a lot:
>> https://bitbucket.org/hsarvell/ext/src/tip/cmd.l?at=default
>>
>> It might give you some ideas.
>>
>> On Thu, Apr 17, 2014 at 10:13 AM,  <> wrote:
>> > Hi, Simon,
>> >
>> > you can use "apply" here:
>> >
>> > (de exe2 (X)
>> >    (apply 'call X) )
>> >
>> > because "call" needs multiple arguments, but not one list.
>> >
>> > Best regards,
>> > Mansur Mamkin
>> >
>> > 17.04.2014 7:17, Simon Luetzelschwab пишет:
>> >
>> >> Hi,
>> >>
>> >> PicoLisp is my first LISP dialect and I'm trying to move some of the
>> >> things I do on the command line to PicoLisp's REPL and scripts
>> >>
>> >> I'm playing around with pipes, in, out and call and have a basic
>> question:
>> >>
>> >> If I have the following fun -
>> >>
>> >> (de exe (X)
>> >>     (eval (cons 'call X)) )
>> >>
>> >> I can call it as follows -
>> >>
>> >> (exe '("ls" "-l"))
>> >>
>> >> However, if I've defined it as -
>> >>
>> >> (de exe2 (X)
>> >>     (call X) )
>> >>
>> >> I can't figure out how to call exe2.
>> >>
>> >> (exe2 '("ls" "-l"))
>> >> ls-l: Can't exec
>> >> -> NIL
>> >>
>> >> I'm pretty sure I shouldn't be using eval for such a case, but can't
>> >> figure it out.
>> >>
>> >> Any insight much appreciated.
>> >>
>> >> Best,
>> >> Simon
>> >>
>> >> PS: I checked the reference, online docs and Henrik's Ext / cmd.l lib
>> >
>> > --
>> > UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>> --
>> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subjectUnsubscribe
>>
>

Reply via email to