Question

I know that there is a lot of similar questions, but neither solved my problem...

So, I would like to execute python script from java using ProcessBuilder...

Here is a method which I wrote and which does not work:

public void stemPosts(String scriptPath, String inputFile, String outputFile)
        throws IOException {
    ProcessBuilder process = new ProcessBuilder("python", scriptPath,
            inputFile, outputFile);
    process.start();
}

And here is method call (<user_path> is just to hidden personal info):

dataManager.stemPosts(
            "D:/<user_path>/stemmer/Croatian_stemmer.py",
            "D:/<user_path>/stemmer/posts.txt",
            "D:/<user_path>/stemmer/stemmedPosts.txt");

First parameter is script, second parameter is first script parameter (inputFile) and third parameter is second script parameter (outputFile)...

Execution in cmd is simple: python Croatian_stemmer.py posts.txt stemmedPosts.txt and that works...

Code above only creates output file but it does not fill it with data...

I tried changing file separators and it did not help...

Was it helpful?

Solution

For starters I would look at what output you see from the execution of the script by redirecting your ProcessBuilder output which is described here.

My hunch would be it's something to do with PYTHONPATH or an error in the script but without seeing either the script or the output of the execution it's impossible to know.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top