tags:

views:

27

answers:

1

Hi,

I am building a standalone using python. This standaloone should execute a ruby file.

I have read this article - http://www.decalage.info/python/ruby_bridge I have used os.system() which works well. But I have an issue here. If a ruby file has some error, file simply terminates without error. Can you please let me know how to GET ruby console output so that I can display the same in my standalone.

A: 

you can use subprocess module

cmd="ruby myrubyscript.rb"                                                                          
p=subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)                              
output, errors = p.communicate()                        

then use the output variable

Just a note, your Python program will be dependent on whether you have Ruby installed or not. If possible, try to do everything in Python.

ghostdog74
Hi user131527,Thanks for the reply. But there seems to be a problem.Output is not getting printed. For e.g. we take a ruby file which has print "Hello world". now i use the code above and print Output. Output is not displayed. Same thing for errors - I mean consider ruby file with syntax error and try to print errors.
abhishek
make sure import subprocess module. make sure your Ruby script actually prints out something.
ghostdog74
i had imported subprocess module and ruby file is working. If i print output -> Blank is displayed and if i print errors -> None is Displayed
abhishek
It Worked.. I just need to add stdout and stderr as PIPE.
abhishek