[squeak-dev] reading and writing from STDIN and STDOUT

Jason Rogers jacaetevha at gmail.com
Tue May 12 20:59:27 UTC 2009


I am competing in a friendly Code Smackdown at work.  Smalltalk vs.
All on-comers (Haskell, Erlang, LISP, Java, C and Python).  The
challenge is to write a client for a Chinese Poker game.

Everything is going well except communicating with the Python-based
server.  I am having trouble reading and writing from STDIN and
STDOUT.  I've installed OSProcess which should give me access to these
streams, but I don't see how to read one line at a time from STDIN and
then get a handle on STDOUT to write a line.  Anyone have pointers or
sample code?

Also, the image needs to be launched by Python with code like...

   subprocess.Popen(["/Application/Squeak/Contents/MacOS/Squeak VM
Opt", "/Users/jrogers/Squeak/images/chinese_poker.image", "Squeak
Client"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)

This will obviously need to change for a server running on another OS.
 The question I have here is how to start a process reading from STDIN
as soon as the VM is fired up.  Should I just create an object that is
waiting on STDIN, reading a line at a time, before saving the image?
That way it would just keep trying to read when the image was fired up
again.

Thanks.

-- 
Jason Rogers

"I am crucified with Christ: nevertheless I live;
yet not I, but Christ liveth in me: and the life
which I now live in the flesh I live by the faith of
the Son of God, who loved me, and gave
himself for me."
    Galatians 2:20



More information about the Squeak-dev mailing list