Before going throw the explanation of my problem, I want to give you a short introduction about my app idea, basically there is a python library that I need to use, and there is no alternatives written in java, my idea was to create the python script which is a simple script to use the lib that facilitate the interaction with another API and even provide more features than the main API. Instead of doing it all myself in java without using the python library, it will cost me too much time, or building the whole application in python/django which I'm not fluent with; So I decided to create the script in python to get the needed data, then use it in java.
When testing the script locally everything was working fine, I run it with ProcessBuilder commands as follow
public static void PythonRunner() throws Exception {
ProcessBuilder processBuilder = new ProcessBuilder("python3", "src/script.py"); // the script is in the src directory
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
InputStream inputStream = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
After that I wanted to host it and try to run it, I found out that it still run on my local computer even if it's hosted in my server, and it was working fine with this code, the rest of it is similar to the code above:
String command = "python3 -c \"import urllib.request; exec(urllib.request.urlopen('" + SCRIPT + "').read()); function_name1('" + params[0] + "'); function_name1('" + params[1] + "')\"";`
`ProcessBuilder processBuilder = new ProcessBuilder("bash", "-c", command);
But after that I deployed the java/spring application on heroku, found out that it can't run the python script "directory script.py not found", after few research I think I should have ssh access to run the script and make it running on the server where it is hosted.
I deployed the script on heroku and tried to run it locally on my computer using the heroku CLI heroku run python3 script.py, but java app can't run it because it doesn't have credentials to my heroku CLI.
Is there any way to host the script and run it within its host via java