How does processing detect when a sketch is running?

Hello, I'm currently making a text editor using processing. I recently added the ability to run processing code directly from the text editor. But I have no control over the program that opens when you compile and run it using the exec() function. Is there any way to control other java applications? I'm asking this on the processing forum because I used the processing compiler to run the code, but if you have any java suggestions feel free to tell me.

Tagged:

Answers

  • But I have no control over the program that opens when you compile and run it using the exec() function

    Your intentions is to control the program that you just started executing? Something like stop executing or re-run it again, exactly as what the PDE does?

    Kf

  • Yes, I want a similar thing to what processing does to its sketches. I want to be able to stop a sketch and know when a sketch is active.

  • Answer ✓

    A bit convoluted but this provides some insight:

    https://github.com/processing/processing/blob/master/java/src/processing/mode/java/JavaEditor.java#L1129

    This is only looking at the java mode. Notice that rebuilding the skecth calls handleStop() in case the window is alive.

    Another lead is internalCloseRunner() which is implemented by the JavaEditor object which extends the Editor object which by definition it is mandated to implement this function. This is more info that what you might need. Check for example: https://github.com/processing/processing/blob/master/app/src/processing/app/ui/Editor.java#L2802

    In other words, Processing keeps an eye on the current running app associated to the current editor (yes, you could have multiple editor windows open): https://github.com/processing/processing/blob/master/java/src/processing/mode/java/JavaEditor.java#L1099

    I am presenting this from the perspective of Processing i.e. based on their design. Can you do it using some java mechanism? I dunno... you should provide the code you are using to launch your "code" from the text editor.

    Kf

  • edited February 2018

    The code I use to run the file is very simple:

    void run() {
      if (files.get(SelectedFile).extension == JAVA) {
        saveText(); // Save the changes to the file
        addPrintThing(); // Some additional code so I can store the console in an accessible file.
        String p = files.get(SelectedFile).file.getPath().replace(files.get(SelectedFile).fileName, "");
        exec("processing-java", "--sketch=" + p, "--run");
      }
    }
    

    this just get's activated whenever someone presses CTRL + R (just like in the processing editor).

    I'll look into your answer, thanks for all the info!

Sign In or Register to comment.