python / ruby​​问题.. [英] python/ruby question..

查看:52
本文介绍了python / ruby​​问题..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...


可以有人指出我在哪里/如何从一个

python应用程序调用ruby应用程序,并且python应用程序能够从ruby脚本获得返回值




类似


test .py

a = os.exec(testruby.rb)

testruby.py

foo = 9

返回foo

i知道这不起作用......但我一直在寻找这个时间与

没有运气....(是的,我对于红宝石/蟒蛇来说都比较新!!!


感谢

解决方案

6月18日,10:33 ???,下午,布鲁斯 < bedoug ... @ earthlink.netwrote:


hi ...


有人能指点我到哪里/我将如何从一个

python应用程序调用一个ruby应用程序,让python应用程序能够从ruby脚本中获得返回值




类似


test.py

??? a = os.exec(testruby.rb)


testruby.py

??? foo = 9

???返回foo

$ b $我知道这不起作用......但是我一直都在寻找这个时间用了

没有运气....(是的,我对这两个红宝石都比较新/ python !!)


谢谢



好​​吧,我对Ruby一无所知,但这里'' s

我是如何为C程序做的(编译为.exe,

写入stdout)。

import os

factor_program =''因素! -d200''#factor!.exe来自MIRACL

n =

''5081842980034330599302211433031103327124931395791 90463526792062622045893426238112366479898891451730 98650749''


#调用外部程序并捕获标准输出

the_output = os.popen(factor_program + n).readlines()


print''n:%s' '%n

我在the_output中:

打印i,


## n:

50818429800343305993022114330311033271249313957919 04635267920626220458934262381123664798988914517309 8650749

## 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


< blockquote> Mensanator写道:


6月18日,10:33 ??? pm,布鲁斯 < bedoug ... @ earthlink.netwrote:


> hi ...

有人能指出我在哪里/怎么样我会从一个
python应用程序中调用一个ruby应用程序,让python应用程序能够从ruby脚本中获取返回值。

类似于

test.py
??? a = os.exec(testruby.rb)

testruby.py
??? foo = 9
返回foo

我知道这不起作用......但我一直在寻找数小时没有运气....(是的,我对ruby / python都比较新!! !!

谢谢



好​​吧,我对Ruby一无所知,但这里是'

我是如何为C程序做的(编译为.exe,

写入stdout)。


import os

factor_program =''因素! -d200''#factor!.exe来自MIRACL

n =

''5081842980034330599302211433031103327124931395791 90463526792062622045893426238112366479898891451730 98650749''


#调用外部程序并捕获标准输出

the_output = os.popen(factor_program + n).readlines()


print''n:%s' '%n

我在the_output中:

打印i,



< snip output>


您应该使用子进程模块。


在这种情况下,类似于:


import subprocess

factor_program = [''factor!'','' - d200'']


....


p = subprocess.Popen(factor_program + [n],stdout = subprocess.PIPE)

p.wait()#等待它完成;不确定它有多必要

the_output = p.stdout.readlines()

请参阅子流程的文档[1],其中包括有关更换的指南

os.popen *以及它的其他功能。


[1]< http://docs.python.org/lib/module-subprocess .html>

-


文章< ma ***************** ********************@python.or g>,

Matt Nordhoff< mn ******* @ mattnordhoff。 comwrote:


>
你应该使用子进程模块。



真的吗? Sez谁?


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

解决方案

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

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 =
''5081842980034330599302211433031103327124931395791 90463526792062622045893426238112366479898891451730 98650749''

# 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:
50818429800343305993022114330311033271249313957919 04635267920626220458934262381123664798988914517309 8650749
## 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


Mensanator wrote:

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

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 =
''5081842980034330599302211433031103327124931395791 90463526792062622045893426238112366479898891451730 98650749''

# 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>
--


In article <ma*************************************@python.or g>,
Matt Nordhoff <mn*******@mattnordhoff.comwrote:

>
You''re supposed to use the subprocess module.

Really? Sez who?


这篇关于python / ruby​​问题..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆