python script runs on its own through terminal but not when it's executed in Java with Runtime.getRuntime().exec()
Question: python script runs on its own through terminal but not when it's executed in
Java with Runtime.getRuntime().exec()

here's my script. i set my python interpreter in Eclipse the proper way and I
don't know what to do.

    
    
    #!/usr/bin python
    
    import subprocess
    
    def execute(command):
        process = subprocess.Popen(command,stdout=subprocess.PIPE, shell=True)
        proc_stdout = process.communicate()[0].strip()
        print (proc_stdout)
    
    execute("command 1", "commnand 2", ...)
    


Answer: I can´t do much without seeing the java code (Most likely the problem is
here).

I still can recommend you not to use "Runtime.getRuntime().exec()", use this
instead (Might solve your problem):

    
    
    String yourCommand = "Python ExampleScript.py";
    ProcessBuilder pb = new ProcessBuilder(yourCommand);
    Process p = pb.start();
    p.waitFor();
    

**Edit:** If you are using complete paths, remember to use this:

(I had the same problem a couple weeks ago)

    
    
    yourCommand.replaceAll("\\\\","/")
    

(I fixed a mistake in the code too)

