Invoking a Ruby program using Python and filename parameter

Question:

I am creating a tool that creates a UI in python using flask. One of the tools functions is to allow a user to upload a CSV file to be processed by a API script. The API is written in Ruby.

How can I pass the data from the python program to the ruby script and possibly return some information about how the data was processed back to the python program to display to the user?

Some hypotheses I had but could use clarification on if they are possible include:

  1. passing the filename as a parameter and invoke the ruby program

  2. Creating a local file(s) to be asynchronously read (and possibly written to by both programs)

Asked By: Josh Sharkey

||

Answers:

You can use a subprocess call for doing this :

call = subprocess.call(["ruby", "path_to_script", "arg1"])

you can add as many arguments as required. If you want to use the output of your ruby script, you can use subprocess.check_output instead of subprocess.call.

Answered By: Aniruddh Chandratre
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.