# Launch() function does not work

**URL:** https://discourse.processing.org/t/launch-function-does-not-work/37459
**Category:** Coding Questions
**Created:** [June 10, 2022, 6:47pm UTC](https://discourse.processing.org/t/launch-function-does-not-work/37459 "2022-06-10T18:47:00Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Logenli](https://avatars.discourse-cdn.com/v4/letter/l/ee7513/32.png) [@Logenli](https://discourse.processing.org/u/Logenli)
#### Post date: [June 10, 2022, 6:47pm UTC](https://discourse.processing.org/t/launch-function-does-not-work/37459/1 "2022-06-10T18:47:00Z")

</div>

**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:

```auto
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!

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [June 10, 2022, 7:45pm UTC](https://discourse.processing.org/t/launch-function-does-not-work/37459/2 "2022-06-10T19:45:10Z")

</div>

> [@Logenli](#):
>
> But I can see “Hi” in my Processing terminal so we know that launchSketch() function is triggered

Clever that you did this!

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [June 10, 2022, 8:07pm UTC](https://discourse.processing.org/t/launch-function-does-not-work/37459/3 "2022-06-10T20:07:16Z")

</div>

Hi,

Maybe you can try to enable [Debugging](https://sojamo.de/libraries/controlP5/reference/controlP5/ControlP5.html#DEBUG) and see if you get further information.

There is also the posibility to get the [Logger](https://sojamo.de/libraries/controlP5/reference/controlP5/ControlP5.html#logger) which you maybe can configure for your needs.

Cheers  
---- mnse

---

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [June 10, 2022, 8:26pm UTC](https://discourse.processing.org/t/launch-function-does-not-work/37459/4 "2022-06-10T20:26:27Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [June 10, 2022, 9:00pm UTC](https://discourse.processing.org/t/launch-function-does-not-work/37459/5 "2022-06-10T21:00:28Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [June 11, 2022, 12:22am UTC](https://discourse.processing.org/t/launch-function-does-not-work/37459/6 "2022-06-11T00:22:06Z")

</div>

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

```auto
//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);
}

```

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [June 13, 2022, 12:09am UTC](https://discourse.processing.org/t/launch-function-does-not-work/37459/8 "2022-06-13T00:09:49Z")

</div>

Hello,

This may be of interest to Windows users:

> [@Can you start a sketch with Arduino button?](https://discourse.processing.org/t/can-you-start-a-sketch-with-arduino-button/37494/12):
>
> Hello, Updates… I did some testing on Windows 10 Pro and added comments to sketch below: // This will launch a Processing 4.0b8 sketch when run on Processing 3.5.4 or 4.0b8: //launch("D:/Program\_Portable/processing-4.0b8/processing-java --sketch=/Users/me/Documents/Processing4b8/Grid\_diagonals\_1\_0\_2 --run"); // This will launch a Processing 3.5.4 sketch when run on Processing 3.5.4 or 4.0b8: //launch("D:/Program\_Portable/processing-3.5.4/processing-java --sketch=/Users/me/Documents/Processin…

Tested on Windows 10 Pro.

`:)`
