1

Is it possible to use Spring Batch to run Python programs? Jython is not an option (because of dependency on many Python libraries).

2 Answers 2

6

The SystemCommandTasklet allows you to execute any shell command you want including a python script if you'd like. You can read the documentation here: http://docs.spring.io/spring-batch/apidocs/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.html

Sign up to request clarification or add additional context in comments.

Comments

0

You can call the python progam as an executable.

A toy python program to do so is:

import java.io.*;
class Interact {

  static public void main(String[] args) throws IOException {
    Process p = Runtime.getRuntime().exec("python3 python_program.py arg1 arg2");
     BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); 
    String line;
    while ((line = in.readLine()) != null) {
        System.out.println(line);
    }
  }
}

if python_program.py is the following

import sys
if __name__ == "__main__"
     print("my args are",sys.argv[1:])

the result should be

my args are ['arg1', 'arg2']

of course on a more complete program you should read the stderr, check the return code etc...

1 Comment

This doesn't address executing Python code from Spring Batch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.