0

I am developing a programm in java, using Eclipse IDE, and I'm trying to run a python script using a java method. This python script will simply write "Test2" in a txt file, so it really won't interfere with anything within my java programm.

The image bellow shows how my packages are organized:

enter image description here

The python script I wish to run is Communication.py, and I used the following method, (called by Systemm.java on the method main) to do so:

    private void runServer() {
        try {
            System.out.println("Im running your py");
            Process p = Runtime.getRuntime().exec("cmd /c python pythonClient\\Communication.py");
        } catch (IOException e) {e.printStackTrace();}
    }

However this method does literally nothing (apart from printing "Im running your py").

I have never really worked with java Runtime's class, and I just copied this command from the internet, so I'd really aprecciate any help, in solving this issue.

P.S: my other classes both py and java are all working smoothly. This is literally the only issue so far

Dreamy
  • 57
  • 9
  • By literally nothing do you mean it doesn't print "Im running your py" either? – Johan Jarvi Jun 06 '21 at 22:59
  • @JohanJarvi let me edit that part yes. Because it does run the print – Dreamy Jun 06 '21 at 23:02
  • Okay another thing that I would check then is it potentially throwing a different exception that you are not catching and therefore it is going unnoticed? Perhaps as part of debugging just catch "Exception" and print that whole stacktrace and then narrow down to catch only the exceptions that you expect to see. Which could be perhaps only the IOException but that's the next thing I would do. – Johan Jarvi Jun 07 '21 at 00:33
  • But it could also be just how it is written in the "exec" function - check the top voted answer to this post: https://stackoverflow.com/questions/10097491/call-and-receive-output-from-python-script-in-java – Johan Jarvi Jun 07 '21 at 00:39
  • @JohanJarvi I did try to catch all the exceptions but still, nothing happened. I believe the issue might really be in hte way I wrote the exec function. I will make sure to check that link :) – Dreamy Jun 07 '21 at 08:04
  • No worries - sorry that I didn't have a proper answer or solution for you I was really just trying to help out with some general programming advice but should've known you had tried that already. Best of luck hopefully you figure it out :) – Johan Jarvi Jun 07 '21 at 21:33

0 Answers0