How can I call python running in shell from ruby. Actually I need ruby to communicate with some app running under the python in shell. So I need ruby to call python (command ‘python’) in cmd and then import libraries (command ‘import xyz’) under the python environment, and thne run functions of this imported libraries (for example ‘xyz.showdate()’), and get result of course.
I tryed to use IO.popen and Open3.popen3 functions to achieve this, but I do something wrong.
Actually I use jruby on rails, but it should be same with ruby, I guess.
You probably don’t really want to be doing this, this is going to make your ruby script excessively convoluted when you could probably get the result directly in ruby.
If you however decide to go that way, you could create a python script that does what you need and run it from the ruby script:
You would then arrange so that your ruby script calls the following command:
Provided your
xyz.showdateprints the date, you can collect standard output to get the result.But again, that’s probably not a great idea.