3

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.

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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.
make sure import subprocess module. make sure your Ruby script actually prints out something.
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
It Worked.. I just need to add stdout and stderr as PIPE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.