RE: python/ruby question..

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bruce

    RE: python/ruby question..

    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.c ompete.com/xxxx/?metrics=uv"

    a = subprocess.Pope n(["/test1/test.rb",pp], stdout=subproce ss.PIPE)
    aa=a.communicat e()[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(:val ue,"Google Search").click
    #puts ff.element_by_x path("//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+bedougl as=earthlink.ne t@python.org
    [mailto:python-list-bounces+bedougl as=earthlink.ne t@python.org]On Behalf
    Of Paul McGuire
    Sent: Thursday, June 19, 2008 6:27 PM
    To: python-list@python.org
    Subject: Re: python/ruby question..


    On Jun 18, 10:33 pm, "bruce" <bedoug...@eart hlink.netwrote:
    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
    --


Working...