python/ruby question..
Mensanator
mensanator at aol.com
Thu Jun 19 00:11:27 EDT 2008
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,
## n:
50818429800343305993022114330311033271249313957919046352679206262204589342623811236647989889145173098650749
## PRIME_FACTOR 37
## PRIME_FACTOR 43
## PRIME_FACTOR 167
## COMPOSITE_FACTOR 507787751
## PRIME_FACTOR 69847
## PRIME_FACTOR 30697
## PRIME_FACTOR 89017
## PRIME_FACTOR 3478697
## PRIME_FACTOR 434593
## PRIME_FACTOR 49998841
## PRIME_FACTOR 161610704597143
## PRIME_FACTOR 14064370273
## COMPOSITE_FACTOR 963039394703598565337297
## PRIME_FACTOR 11927295803
More information about the Python-list
mailing list