Howto embed newlisp in (shell) programs part 2

Started by pjot, April 05, 2008, 02:35:10 AM

Previous topic - Next topic

pjot

Hi,



Pending the issue of the http://www.alh.net/newlisp/phpbb/viewtopic.php?t=2243">previous post, I tried to solve it in a different way.



Similar to other core Unix programs, I tried to use a pipe to the STDIN of newLisp, but it fails. Below taken from the command prompt:
Quote
peter[~]$ echo "help" | awk '{print}'

help

peter[~]$ echo "help" | sed {}

help

peter[~]$ echo "help" | cut -f1

help

peter[~]$ echo "help" | newlisp -e "(println)"



nil


So how can I accept stdin to the newLisp binary and perform a task with it?



If newLisp wants to integrate in a Unix environment then it would be great if this works!



Thanks

Lutz

#1
not necessary, see my answer to your previous post, we posted at the same time.

Lutz

#2
and here is the solution to your pipe problem:


~> echo "help" | newlisp -e "(read-line)"
"help"
~>

pjot

#3
Hi Lutz,



Indeed, the solution works fine!



However, just for arguments sake, how would you think about implementing a STDIN for newLisp? It would help a lot in different (Unix) situations if this is possible.



Just curious on your ideas about this.



Thanks

Peter

pjot

#4
You're fast! It always worked, thanks a lot!



Complete list now:


Quote
peter[~]$ echo "help" | awk '{print}'

help

peter[~]$ echo "help" | sed {}

help

peter[~]$ echo "help" | cut -f1

help

peter[~]$ echo "help" | newlisp -e "(read-line)"

"help"


Peter

Lutz

#5
In this chapter: http://www.newlisp.org/CodePatterns.html#scripts">http://www.newlisp.org/CodePatterns.html#scripts you find the basic pattern of a UNIX filter written in newLISP:


~> echo "hello world" | ./filter
HELLO WORLD

~> cat filter
#!/usr/bin/newlisp

(while (read-line) (println (upper-case (current-line))))

(exit)

~>


'current-line' always contains the last result from 'read-line'. This pattern has been well tested in a UNIX environment. It also works with inetd for setting up servers.



ps: I am on your timezone ;-)

pjot

#6
Aha! I was already wondering why you were responding so fast ;-)



Maybe time for another European Newlisp Conference? ;-)

Lutz

#7
QuoteMaybe time for another European Newlisp Conference? ;-)


Sure!