stdin/stdout in console applications

Edi Weitz <[email protected]>
Newsgroups gmane.lisp.corman
Message-ID <[email protected]>
Hi!

This message will show my complete ignorance about Windows issues and is 
probaly only marginally related to Corman Lisp but, anyway, here it goes...

I want/need to write a little console application that acts like a Unix 
"filter", i.e. it reads from stdin and writes to stdout. I wanted to 
start small and wrote the simplest app I could imagine - something that 
just lets everything go through. So, here's my only function:

(defun main ()
   (loop for line = (read-line *standard-input* nil)
         while line
         do (format *standard-output* "~A~%" line)
            (force-output *standard-output*))
   (print 'done *standard-output*)
   (force-output *standard-output*))

I created an EXE file with

(save-application "foo" 'main :console t :static t)

However, this raises lots of questions:

1. If I start this from a console window it does what I expect, i.e. it 
echos back the lines I type. But I don't know how to stop it - neither 
Ctrl-D nor Ctrl-Z work. How do I send an EOF from the console?

2. If I start it like "foo.exe < some_file.txt" I see nothing at all. 
The program just hangs. What's happening?

3. If I start it like "dir | foo.exe" I see the output from dir but the 
programm crawls. It also hangs at the end of the directory listing and 
doesn't stop nor does it show the DONE line. Again, what's happening? 
And why is it so slow?

4. Is this the right way to write such a program? I mean, can I expect 
the program to end when my MAIN function is finished or do I have to 
call some kind of EXIT function?

5. I recall having read something about setting the mode (?) of stdin 
and stdout to binary under Windows. Is that an issue here?

Sorry for (almost) half a dozen of dumb questions.

Thanks in advance,
Edi.


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/LIgTpC/vN2EAA/xGHJAA/SyjtlB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[email protected]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.