python/ruby question..

Michael Mabin d3vvnull at gmail.com
Thu Jun 19 10:24:53 EDT 2008


The commands module might help you out as well.
import commands as c
output = c.getoutput('testruby.rb')



On Thu, Jun 19, 2008 at 5:14 AM, Matt Nordhoff <mnordhoff at mattnordhoff.com>
wrote:

> Mensanator wrote:
> > 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.
> >>
> >> something like
> >>
> >> test.py
> >> �a = os.exec(testruby.rb)
> >>
> >> testruby.py
> >> �foo = 9
> >> �return foo
> >>
> >> i know this doesn't work... but i've been searching for hours on this
> with
> >> no luck.... (and yeah, i'm relatively new to both ruby/python!!)
> >>
> >> thanks
> >
> > Well, I don't know anything about Ruby, but here's
> > how I do it for C programs (compiled to .exe that
> > write to stdout).
> >
> >
> > import os
> > factor_program = 'factor! -d200 ' # factor!.exe from MIRACL
> >
> > n =
> >
> '50818429800343305993022114330311033271249313957919046352679206262204589342623811236647989889145173098650749'
> >
> > # call external program and capture stdout
> > the_output = os.popen(factor_program+n).readlines()
> >
> > print 'n: %s' % n
> > for i in the_output:
> >     print i,
>
> <snip output>
>
> You're supposed to use the subprocess module.
>
> In this case, something like:
>
> import subprocess
> factor_program = ['factor!', '-d200']
>
> ...
>
> p = subprocess.Popen(factor_program + [n], stdout=subprocess.PIPE)
> p.wait() # wait for it to finish; not sure how necessary it is
> the_output = p.stdout.readlines()
>
> See subprocess's documentation [1], which includes guides on replacing
> os.popen* and other functions with it.
>
> [1] <http://docs.python.org/lib/module-subprocess.html>
> --
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080619/090fb474/attachment-0001.html>


More information about the Python-list mailing list