# Launch() exec() command on linux

**URL:** https://discourse.processing.org/t/launch-exec-command-on-linux/45174
**Category:** Coding Questions
**Created:** [October 13, 2024, 10:08am UTC](https://discourse.processing.org/t/launch-exec-command-on-linux/45174 "2024-10-13T10:08:33Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Seamiki](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@Seamiki](https://discourse.processing.org/u/Seamiki)
#### Post date: [October 13, 2024, 10:08am UTC](https://discourse.processing.org/t/launch-exec-command-on-linux/45174/1 "2024-10-13T10:08:33Z")

</div>

I want to send a terminal command from my sketch using launch() or exec() but i am facing issues in both cases:  
when i use

```auto
launch("echo \"Hai\" >> /dev/usb/lp0");

```

looks like it tries to open a folder instead of executing the command  
and i get the error  
“The file or folder /home/user/processing-4.3/echo “Hai” \>\> /dev/usb/lp0 does not exist.”

when i use:

```auto
exec("echo \"Hai\" >> /dev/usb/lp0");

```

i get the following exeption:  
“java.lang.RuntimeException: Exception while attempting echo “Hai” \>\> /dev/usb/lp0  
at processing.core.PApplet.exec(PApplet.java:3193)  
at SerialCallResponse.mousePressed(SerialCallResponse.java:45)  
at processing.core.PApplet.mousePressed(PApplet.java:2425)  
at processing.core.PApplet.handleMouseEvent(PApplet.java:2371)  
at processing.core.PApplet.dequeueEvents(PApplet.java:2261)  
at processing.core.PApplet.handleDraw(PApplet.java:2104)  
at processing.awt.PSurfaceAWT$9.callDraw(PSurfaceAWT.java:1386)  
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:356)  
Caused by: java.io.IOException: Cannot run program “echo “Hai” \>\> /dev/usb/lp0”: error=2, No such file or directory  
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)  
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)  
at java.base/java.lang.Runtime.exec(Runtime.java:594)  
at java.base/java.lang.Runtime.exec(Runtime.java:453)  
at processing.core.PApplet.exec(PApplet.java:3191)  
… 7 more  
Caused by: java.io.IOException: error=2, No such file or directory  
at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)  
at java.base/java.lang.ProcessImpl.(ProcessImpl.java:314)  
at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:244)  
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110)  
… 11 more”

I am running Linux Kde Neon.  
below is the code i am trying to run:

```auto
void setup() {
  size(200, 200);
}

void draw() {
  // draw() must be present for mousePressed() to work
}

void mousePressed() {
  println("Opening Process_4");
  try{
    exec("echo \"Hai\" >> /dev/usb/lp0");
    //launch("echo \"Hai\" >> /dev/usb/lp0");
  }catch (RuntimeException e) {
    e.printStackTrace();
  }
}

```

I appreciate any help

---

<div class="post-metadata">

### Author: ![Seamiki](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@Seamiki](https://discourse.processing.org/u/Seamiki)
#### Post date: [October 13, 2024, 10:26am UTC](https://discourse.processing.org/t/launch-exec-command-on-linux/45174/2 "2024-10-13T10:26:59Z")

</div>

I found a solution (with chatGPT ☺).

```auto
String command = "echo 'Hai' >> /dev/usb/lp0"; //terminal command

void setup() {
  size(200, 200);
  
}

void draw() {
  // draw() must be present for mousePressed() to work
}

void mousePressed() {
  println("Opening Process_4");
  try{
    exec("bash", "-c", command);
  }catch (RuntimeException e) {
    e.printStackTrace();
  }
}

```

launch() doesn’t seem to work but exec() does.  
hope it might be useful for someone facing the same issue.
