I want capture the stdou result created my the process it self
like
#!/usr/bin/newlisp
;
; - inout -
; read from stdin 0 into buffer
; than write to stdout 1
;
; USAGE: ./inout < inputfile > outputfile
;
(print "Hello")
(while (read 0 buffer 1024)
(write 1 buffer 1024))
(exit)
But this code never works, it always be waiting
I dont want to do it like echo hello | t newlisp inout.lsp
Anyone have a better way?
thanks
works for me on Mac OS X:
~> echo hello | newlisp inout
hello
~> echo hello | ./inout
hello
~>
and also on Windows XP:
C:Documents and SettingsLutz>echo hello | newlisp inout
hello
C:Documents and SettingsLutz>
The other way would be as shown in the comments with redirects from to files.
Not sure why you have that extra (print "Hello") in your code? What OS are you using?
I am on linux
That's not What I want
I just want to run it ,and the result of (print "hello") inside the inout can be showed
Not echo hello | ./inout
just like
#./inout
and hello shows up
I want capture the print result inside the program ,not from outside like ech cat ,etc...
Cause in fastcgi
I better to captured the length of stdout result
you know
all fastcgi result is created by print println ,etc, some basic functions
if I cant get the length of stdout,it'll be very hard to do fastcgi in newlisp
Since now I redirect all print result to a file in /tmp
but this way is not perfect,and it's slower than php
I want to capture all stdout result in a buffer , a buffer of memory ,that's the fastest way.
That would look like this:
#!/usr/bin/newlisp
(print "Hello")
(exit)
running:
~> ./inout
Hello~>
and the length?
You cant know the length of print ,all of the prints
> (length "hello")
5
>
You just cant get it ,right?
I assum I dont know the content of print
(print anything I do not know)
how u get the length?
I will have hunders print
generated by (eval-string lsp_file)
I want the length of result
also
(catch) only return the last result of newlisp
like for 1000
the 1000 times result returned
it's so close, I nearly did the fastcgi part
Maybe it is wrong to develop fastcgi on newlisp ,I should do it in C ,like php-cgi
what a pity
https://github.com/guu/newlisp-fastcgi
instead of using 'print 'you could use the second syntax of 'write' printing to a string in memory. This way you can either accumulate the return values from 'write' as the number of characters printed or take the (length buffer), where 'buffer' is the string buffer, you wrote to:
(set 'buffer "") ; init buffer to empty string
(write buffer stuff-to-write)
(write buffer other-stuff)
(set 'n-of-bytes-written (length buffer))
or do:
(inc cnt (write buffer stuff))
then finally write buffer to stdout:
(write 1 buffer cnt)
I know there are many way to skip this problem
But what I do is a host , running with nginx ,etc httpd
I could do my code ,but I cant control pepole to write my code
for example:
When I found out the bug in my prev version of fastcgi is
http://www.newlisp.org/environment.cgi
I put it into my server, then I see, the do-list loop results did not show up.
so I got it , my code has problems
and I also can not set env QUERY_STRING and else env vars with my code
I think this problem can not be skipped.
I must found a way to get all stuff printed by eval-string ,at least the length , so that
my code can run the old newlisp cgi code to fastcgi mode.
AM I RIGHT?
If it is not able to be done in newlisp ,tell me ,so I can change my way.
Dexter, I've been wanting FastCGI for newlisp for a while. I'm excited to see you here. Can you phone me? I'll send it to you in private message here on the forum. Or send me your number. Maybe I can help.
Since you are already doing FastCGI, I recommend leaving the CGI module alone completely. How much code would you need to convert from using the CGI module?
Do u have msn or gtalk?
dexterkidd$gmail.com/msn.com
I am doing it in another way now