Launch() function does not work

Objective:

I want to activate/run another processing script using controlp5 button. When users click the button, they can trigger the target script.

What I have so far:
Here is my code:

import controlP5.*;

void setup(){
  new ControlP5(this).addButton("launchSketch").setLabel("launch\nsketch")
  .setSize(100, 100).setPosition(0,0);
}

void draw(){}

void launchSketch(){
  print("Hi");
  launch("processing-java","--sketch=/absolute/path/to/targetSketch.pde","--run");
}

Issues:

  1. The button works fine. However, when I click it, nothing happens. No script is launched. But I can see “Hi” in my Processing terminal so we know that launchSketch() function is triggered
  2. I also tried exec() function, turns out it will just crash the application.

System I am using:
Mac M1, Processing 4; But I also tried my non-M1 mac with Processing 3. Not working.

@svan
Thanks for the reply. Now it works! However, when I clicked the controlp5 button, it actually opens two target script windows instead of one. This is one last issue I need to figure it out!

Clever that you did this!

1 Like

Hi,

Maybe you can try to enable Debugging and see if you get further information.

There is also the posibility to get the Logger which you maybe can configure for your needs.

Cheers
---- mnse

1 Like

Try running your arguments in Terminal. processing-java is in usr/local/bin on my system. When I try to run it with ./ I get this error: /Applications/Processing.app/Contents/PlugIns/jdk-11.0.12+7/Contents/Home/bin/java: No such file or directory. My Processing app has jdk-17.0.2+8 which is not the version its looking for.

1 Like

This works from the command-line on my system: processing-java --sketch=/Users/yourName/Documents/Processing/mySketchFolder --run but so far can’t run it with launch(). You’ll need to get the most recent processing-java by selecting it from the Tools menu. Also with ‘sketch’ stop with the folder; don’t add xxxx.pde (sketch name).

2 Likes

Doesn’t solve your problem with launch(), but I found this on StackOverflow and it works on my system:

//https://stackoverflow.com/questions/47026297/use-processing-java-in-runtime-getruntime-exec

String sketchpath = "/Users/yourName/Documents/Processing/sketchFolder";

String cmd = "usr/local/bin/processing-java --sketch=" + sketchpath + " --run";

println(cmd);
try {
  Runtime.getRuntime().exec(cmd);
}
catch(Exception e) {
  println(e);
}
1 Like

Hello,

This may be of interest to Windows users:

Tested on Windows 10 Pro.

:)