python under java2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • motokoit

    #1

    python under java2

    For some reason i need to start a python script from inside a java code. The
    main part of the code is something like this

    try{
    Runtime rt = Runtime.getRunt ime();
    System.out.prin tln("start");
    Process proc = Runtime.getRunt ime().exec("pyt hon myscript.py");
    proc.waitFor();
    System.out.prin tln("end");
    } catch (Exception e){
    e.printStackTra ce();
    }

    and so worked for months....but since some days ago the same instruction
    does not work but execute without any exception, that is print either
    "start" and "end"; the strangest thing happen when I call just

    Process proc = Runtime.getRunt ime().exec("pyt hon myscript.py");

    the execution looks like stalled and does not comes to an end printing just
    the "start".

    Some suggestion?
    My machine is a Linux Mandrake64 10.1




  • Steve Horsley

    #2
    Re: python under java2

    motokoit wrote:[color=blue]
    > For some reason i need to start a python script from inside a java code. The
    > main part of the code is something like this
    >
    > try{
    > Runtime rt = Runtime.getRunt ime();
    > System.out.prin tln("start");
    > Process proc = Runtime.getRunt ime().exec("pyt hon myscript.py");
    > proc.waitFor();
    > System.out.prin tln("end");
    > } catch (Exception e){
    > e.printStackTra ce();
    > }
    >
    > and so worked for months....but since some days ago the same instruction
    > does not work but execute without any exception, that is print either
    > "start" and "end"; the strangest thing happen when I call just
    >
    > Process proc = Runtime.getRunt ime().exec("pyt hon myscript.py");
    >
    > the execution looks like stalled and does not comes to an end printing just
    > the "start".
    >
    > Some suggestion?
    > My machine is a Linux Mandrake64 10.1
    >[/color]
    I think this is probably really a java question. I suspect that your
    python script is issuing too much output either on stdout or stderr,
    and because you are not reading these streams, the process is blocking
    because the output buffers are full. If this is the case, you need to
    get your java program to read the streams (Process.getInp utStream()
    and Process.getErro rStream()), which is something you should be doing
    anyway. In order to read both streams, you either need two threads, or
    to use java.nio and select.

    A short term fix might be to run theh python script by hand and see if
    it throws out a long stack trace (this could block an unread error stream).

    HTH
    Steve

    Comment

    Working...