python/ruby question..

bruce bedouglas at earthlink.net
Fri Jun 20 04:10:06 CEST 2008


hey guys...

i managed to solve what i was attempting.. my goal was rather simple, to be
able to have a python script, call a ruby app, and be able to return  a
value from the ruby (child) app to the parent.. blocking/unblocking wasn't
on my radar for now.

ultimately, my goal is to have an app on a master server, with that app
calling the ruby app using the remote functions (rsh/rexec for now).

so, on the master python, i have:
#!/usr/bin/python

#test python script
import re
import os
import sys, string
import os.path
import subprocess

#print "foo"
pp="http://siteanalytics.compete.com/xxxx/?metrics=uv"

a = subprocess.Popen(["/test1/test.rb",pp], stdout=subprocess.PIPE)
aa=a.communicate()[0]
qq=aa.split("\n")
print "qq[8] = ",qq[8]
print "qq[9] = ",qq[9]
print "qq[10] = ",qq[10]
#exit()

and on the child/ruby app:
#! /usr/local/bin/ruby

require 'rubygems'
require '/usr/local/lib/ruby/gems/1.8/gems/firewatir-1.1.1/firewatir'
include FireWatir

a1=ARGV[0]

ff=Firefox.new
ff.goto(a1)
table = ff.table(:id, "dataTable").to_a
#puts table
#puts "blah...."
aa = table[1][1]
puts table[1][1]

#ff.text_field(:name, "q").set("ruby")
#ff.button(:value,"Google Search").click
#puts ff.element_by_xpath("//a[@class='l']").text
#ff.close
#puts "hi there"
#return (33)


this pretty much works as it needs to for now...

like i said.. rather simple, as it should be.

so thanks for the help/suggestions from everyone!



-----Original Message-----
From: python-list-bounces+bedouglas=earthlink.net at python.org
[mailto:python-list-bounces+bedouglas=earthlink.net at python.org]On Behalf
Of Paul McGuire
Sent: Thursday, June 19, 2008 6:27 PM
To: python-list at python.org
Subject: Re: python/ruby question..


On Jun 18, 10:33 pm, "bruce" <bedoug... at earthlink.net> wrote:
> hi...
>
> can someone point me to where/how i would go about calling a ruby app from
a
> python app, and having the python app being able to get a returned value
> from the ruby script.
>

I'm betting that Ruby is similar to Python in that a Ruby interpreter
can be embedded within other applications.  Why not implement
something like ruby_exec(), similar to Python's exec, which takes a
string containing Ruby code, and a dict of variables that can be
accessed and updated from the executed Ruby?  Then no messing around
with subprocess, XMLRPC, firing up processes, etc. - just create the
string and call it.

(Implementation left as an exercise for the reader.)

-- Paul
--
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list