Best way to execute ruby ​​file using Python and how to get ruby ​​console output when ruby ​​file is launched from python?

I am creating a standalone using python. In this offline mode, a ruby ​​file must be executed.

I read this article - http://www.decalage.info/python/ruby_bridge I used os.system (), which works well. But I have a problem. If there is some error in the ruby ​​file, the file simply exits without errors. Could you let me know how to get the GET console output so that I can display the same in my offline mode.

+3
source share
1 answer

you can use the subprocess module

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

then use the variable output

, Python , Ruby . , Python.

+5

Source: https://habr.com/ru/post/1767977/


All Articles