On Wed, 24 Sep 2008, Jeff Hodges wrote:
> Hugh Sasse wrote:
> > Is IO.popen supposed to be working OK?
> >
> > I'm getting errors with
> >
> >
> > PYTHON = "C:/cygwin/usr/bin/python"
> > PYTHON_PROG = "-../AnnaAIML-.7.0/anna_brain/skel.py"
> > MODE = "w+"
> > PAUSE = 30
> >
> > def setup_program
> > if block_given?
> > Open3.popen3(PYTHON_PROG, MODE) do |io|
> > sleep PAUSE
> > ignore = io.read
> > yield io
> > end
> > else
> > @io = IO.popen(PYTHON_PROG, MODE) #<----- Errors here
> > # ignore = @io.read
> > end
> > end
> >
> > with either No such file or directory" if the - is at the start, or exec
> > format error if it points to the python script with a #!python
> > line. Yes, I'm trying to use ruby's interpretation of the #! line
> > to spin off a python program. So why it is treating this as a
> > file path spec rather than a command string? The ri docs talk
> > about it being a command string. If I put a path
> > to the Python in there using #{PYTHON} it can't find the file with a space:
> > "#{PYTHON} ../"...
> >
> > So I've tried:
> >
> > PYTHON_PROG = "-../AnnaAIML-.7.0/anna_brain/skel.py"
> > PYTHON_PROG = "../AnnaAIML-.7.0/anna_brain/skel.py"
> > PYTHON_PROG = "#{PYTHON} ../AnnaAIML-.7.0/anna_brain/skel.py"
> >
> > all without success.
> >
> > This is not mission critical for me, I'm just messing about with PyAIML
> > and Shoes, but I'd like to know why my assumptions about popen and popen3
> > are bonkers. I'd use expect.rb
> > http://www.ruby-doc.org/stdlib/libdoc/pty/rdoc/index.html
> > but I'm fairly sure that won't work on Windows.
> >
> > Hugh
>
> It looks like the directory you think you are in is not the directory you
> actually are in. I'd suggest playing around with checking what __FILE__ is in
Oh, right, I'm still thinking of Unix scripts that know where they are
when you invoke them. This is probably it, though the error messages
are a bit odd.
> this program, etc., as Shoes does tricksy eval things that can trip people up.
>
> First though, I would suggest using absolute paths everywhere (even if you
> have to hard code them in) in order to make sure your code works as you
> expect. Since you're playing with new unfamiliar bits like Shoes, it can be a
> bit difficult to hold all that in your head while also maintaining the mental
> model of "where Shoes puts you" on the filesystem. Absolute paths reduce that
> overhead and, since you seem to be writing a one-off program, it won't cause
> too much technical debt.
No, that's OK, but the concision of relative paths would be nice to have
in future.
>
> Later, you can work out your own tricksy File.dirname(__FILE__) (or, blech,
> FileUtils.chdir) things.
>
> Also, w+ indicates that you are able to write to the pipe, not just read it as
> you are (attempting) to do. I would suggest changing this to 'r' for both
Yes, I'm trying to send text to it and have it respond. PyAIML is a chatterbot.
I've found with Shoes you can speak (using the Windows speech recognition
in Vista) into the edit boxes directly, which you can't do in Python, so
I'm seeing if I can make a chatterbot you can chat with. The illusion
won't last long of course, but it might be entertaining enough to put on
the Shoebox.
> clarity's sake and to prevent accidental write attempts. You are only going to
> be reading from it (since it's the output of another program), and it's best
> to treat it that way.
> --
> Jeff
>
Hugh