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:
-
passing the filename as a parameter and invoke the ruby program
-
Creating a local file(s) to be asynchronously read (and possibly written to by both programs)
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
.
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:
-
passing the filename as a parameter and invoke the ruby program
-
Creating a local file(s) to be asynchronously read (and possibly written to by both programs)
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
.