I dug the internet a lot and found the solution.

One can do this using the following commands:

String fetching = "python " + "c:\\Fetch.py \"" + songDetails + "\"";
String[] commandToExecute = new String[]{"cmd.exe", "/c", fetching};
Runtime.getRuntime().exec(commandToExecute);
Answer from metamemelord on Stack Overflow
Discussions

[ask] how to communicate with python with spring boot.
Hello sir. This term I wanna develop a project with both python and java. I'd like to use spring boot to do the web part, but there's a tough problem for me. I 've already finish the da... More on github.com
🌐 github.com
5
April 6, 2019
How to call an internal Python service for a Java-based Spring Boot project - Stack Overflow
I have to execute a Python script from the inside of a Spring Boot project. The script should be pretty easy but was made by other people and if possible I want to avoid the needing of change it. ... From my Java code I execute a shell command, something like shown here: https://www.baeldung.com/run... More on stackoverflow.com
🌐 stackoverflow.com
August 1, 2020
Run python script
Hello everyone, I am trying to execute a python script from a spring boot project. I tried the following and seems like it is not working even though I am not getting any error. Could some one guide on a way to do the task? here is what i tried. package Python; import org.camunda.bpm.engin... More on forum.camunda.io
🌐 forum.camunda.io
0
1
May 19, 2021
How to run python script (and receive output) from java/spring-boot project which is inside a docker container? - Stack Overflow
Namely, I am trying to run a python script inside of my Java Spring Boot Application, capture the output of the Python, and then display the text. This works fine on my local machine , but when I build it on the docker base image and run it, nothing happens (i.e. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Baeldung
baeldung.com › home › java › how to call python from java
How to Call Python From Java | Baeldung
August 27, 2025 - In this tutorial, we'll see how to orchestrate a multi-step flow for a ride-hailing application by integrating Dapr Workflows and Spring Boot: ... Python is an increasingly popular programming language, particularly in the scientific community due to its rich variety of numerical and statistical packages. Therefore, it’s not an uncommon requirement to be able to invoke Python code from our Java applications.
🌐
GitHub
github.com › amemifra › Spring-Jython
GitHub - amemifra/Spring-Jython: Java integration of Python script and classes into a Spring Boot Web Application. Powered by Jython · GitHub
Java integration of Python script and classes into a Spring Boot Web Application. Powered by Jython - amemifra/Spring-Jython
Starred by 11 users
Forked by 11 users
Languages   Python 99.3% | Java 0.7%
🌐
GitHub
github.com › hendisantika › ask-me-anything › issues › 3
[ask] how to communicate with python with spring boot. · Issue #3 · hendisantika/ask-me-anything
April 6, 2019 - Hello sir. This term I wanna develop a project with both python and java. I'd like to use spring boot to do the web part, but there's a tough problem for me. I 've already finish the da...
Author   LEODPEN
🌐
Medium
jxausea.medium.com › spring-boot-integrated-python-engine-quick-start-demo-24d3f96cc4aa
Spring boot integrated python engine quick start demo | by HBLOG | Medium
March 12, 2024 - package com.et.python; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } https://github.com/Harries/springboot-demo · package com.et.python.util; import org.python.util.PythonInterpreter; public class JavaRunPython { public static void main(String[] args) { PythonInterpreter interpreter = new PythonInterpreter(); interpreter.exec("a='hello world'; "); interpreter.exec("print a;"); } } result · hello world · create a python script in resource/py directory,file named test.py,file contents as follows: ·
🌐
Dreamix
dreamix.eu › home › insights › tech › how to use jython with spring boot
How to use Jython with Spring Boot - Dreamix
July 16, 2024 - It fully covers the python language and has the pip module manager. From my experience working in an bespoke development company, Spring is the de facto standard for enterprise applications in the recent years and by using interfaces and dependency injection we can seamlessly integrate our code with the existing java codebase. This way we can get the best out of both worlds and create even better products. In my example I will create a Spring Boot application with a service which is implemented in Jython.
🌐
Medium
medium.com › @kiarash.shamaii › integrating-a-simple-python-model-with-a-spring-boot-application-ddaf372831a7
Integrating a Simple Python Model with a Spring Boot Application | by kiarash shamaii | Medium
September 1, 2024 - package kia.shamaei.serverapp.service; import kia.shamaei.serverapp.controller.dto.PredictResponseDto; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.PumpStreamHandler; import org.springframework.stereotype.Service; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.InputStreamReader; /** * Service class for making predictions using a Python script.
Find elsewhere
🌐
YouTube
youtube.com › watch
Empower your Spring Applications with Python Features on GraalVM by Johannes Link @ Spring I/O 2023 - YouTube
Spring I/O 2023 - Barcelona, 18-19 MayGitHub repo: https://github.com/EXXETA/springio-2023GraalVM is mainly known for its native image-compiler. But it provi...
Published   July 12, 2023
🌐
Camunda
forum.camunda.io › camunda 7 topics › discussion & questions
Run python script - Discussion & Questions - Camunda Forum
May 19, 2021 - Hello everyone, I am trying to execute a python script from a spring boot project. I tried the following and seems like it is not working even though I am not getting any error. Could some one guide on a way to do the task? here is what i tried. package Python; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; public class RunPythonScript implements JavaDelegate{ @Override public void execute(DelegateExecution execution) throws...
🌐
GitHub
github.com › GoogleContainerTools › jib › issues › 4185
Hi, I am trying to call the python script from Spring boot Java application which is containerized with Google Jib. · Issue #4185 · GoogleContainerTools/jib
February 13, 2024 - I am trying to call a python script for some business purposes which is containerized with Google Jib. I would like to know how can I copy python into the jib if it's possible , so that it will allow me to call the script from the applic...
Author   NitinSharma1991
🌐
Quora
quora.com › How-do-I-call-Python-script-from-Java
How to call Python script from Java - Quora
Answer (1 of 4): The old approach. [code]Process p = Runtime.getRuntime().exec("python yourapp.py"); [/code]You can read up on how to actually read the output here: http://www.devdaily.com/java/edu/pj/pj010016 There is also an Apache library (the Apache exec project) that can help you with thi...
🌐
Blender Artists
blenderartists.org › coding › python support
Spring boot call machine learning python script - Python Support - Blender Artists Community
October 15, 2020 - I developed rest API project in java with spring framework and I also developed machine learning for spam detection in python with nltk library it gets a string and detects if its spam or not now I want to call my machine learning in my spring framework but I don’t want that in each call ...
Top answer
1 of 4
2
You can use Java Runtime.exec() to run python script, As an example first create a python script file using shebang and then set it executable.#!/usr/bin/python import sys print ('Number of Arguments:', len(sys.argv), 'arguments.') print ('Argument List:', str(sys.argv)) print('This is Python Code') print('Executing Python') print('From Java')if you save the above file as script_python and then set the execution permissions usingchmod 777 script_pythonThen you can call this script from Java Runtime.exec() like belowimport java.io.*; import java.nio.charset.StandardCharsets; public class ScriptPython { Process mProcess; public void runScript(){ Process process; try{ process = Runtime.getRuntime().exec(new String[]{"script_python","arg1","arg2"}); mProcess = process; }catch(Exception e) { System.out.println("Exception Raised" + e.toString()); } InputStream stdout = mProcess.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(stdout,StandardCharsets.UTF_8)); String line; try{ while((line = reader.readLine()) != null){ System.out.println("stdout: "+ line); } }catch(IOException e){ System.out.println("Exception in reading output"+ e.toString()); } } } class Solution { public static void main(String[] args){ ScriptPython scriptPython = new ScriptPython(); scriptPython.runScript(); } }Hope this helps and if not then its recommended to join our Java training class and learn about Java in detail.
2 of 4
0
There are three ways to get this done:runtime approachprocess approachjython approachHave a look at this blog for detailed explanation with example.
🌐
Spring
docs.spring.io › spring-python › 1.2.x › sphinx › html › remoting.html
8. Remoting — Spring Python v1.2.1.FINAL documentation
Due to minimal functionality provided by Caucho’s Hessian library for Python, there is minimal documentation to show its functionality. The following shows how to connect a client to a Hessian-exported service. This can theoretically be any technology. Currently, Java objects are converted intoPpython dictionaries, meaning that the data and transferred, but there are not method calls available:
🌐
Reddit
reddit.com › r/javahelp › running python script with webapp with spring boot backend
r/javahelp on Reddit: Running Python Script with WebApp with Spring Boot Backend
December 4, 2024 -

Hello everyone.. i want to ask is it possible to add a python script like this?

I have a functional spring boot + react app for users and they already using it. But they have a new change request to add a button to download the file as an excel with templates and data was fetch from the db. My friend help me by building a python script to generate this file (since we think python is good for working with data)

Is it possible to add a button in my react front end to run the python script and download the data as excel?

Top answer
1 of 2
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2 of 2
1
JYthon is a Java implementation of python 2.7. Beyond that, you're into executing an external process from your Spring backend. https://www.baeldung.com/java-process-api Either way is probably a lot more hassle than simply re-writing that Python in Java. I guess a third approach would be to turn that python script into a web app using Flask or something, and have your Spring backend call it. But it's all a lot of fuss, with you now having to manage failure modes which simply wouldn't happen if it was all done in-process. Having some Java do it natively in the Spring backend is far simpler. Apache POI makes working with Excel easier, and I think there are other libraries around.