arduino/Arduino · error · RuntimeException

'Could not open ' + join(argv, ' ')

Error message

'Could not open ' + join(argv, ' ')

What it means

PApplet.exec launches an external process via Runtime.getRuntime().exec(argv) and, if that throws any Exception, wraps the failure in a RuntimeException "Could not open <argv joined by spaces>". It is used by PApplet.open to open files/URLs with the platform's default handler. The original exception is printed to stderr before the RuntimeException is thrown.

Source

Thrown at arduino-core/src/processing/app/legacy/PApplet.java:430

      // If the 'open', 'gnome-open' or 'cmd' are already included
      if (params[0].equals(argv[0])) {
        // then don't prepend those params again
        return exec(argv);
      } else {
        params = concat(params, argv);
        return exec(params);
      }
    } else {
      return exec(argv);
    }
  }

  static public Process exec(String[] argv) {
    try {
      return Runtime.getRuntime().exec(argv);
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException("Could not open " + join(argv, ' '));
    }
  }

  static public String[] concat(String a[], String b[]) {
    String c[] = new String[a.length + b.length];
    System.arraycopy(a, 0, c, 0, a.length);
    System.arraycopy(b, 0, c, a.length, b.length);
    return c;
  }

  /**
   * Identical to match(), except that it returns an array of all matches in
   * the specified String, rather than just the first.
   */
  static public String[][] matchAll(String what, String regexp) {
    Pattern p = Pattern.compile(regexp, Pattern.MULTILINE | Pattern.DOTALL);
    Matcher m = p.matcher(what);
    ArrayList<String[]> results = new ArrayList<>();

View on GitHub (pinned to a0df6e0e83)

Solutions

  1. Check stderr for the underlying IOException printed before the RuntimeException — usually 'Cannot run program: No such file'
  2. Install the platform opener (e.g. xdg-utils on Linux for xdg-open)
  3. Verify the file/URL you are opening exists and the command array is well-formed
  4. Wrap open() calls and fall back to an explicit command (e.g. firefox <url>) when the runtime exception occurs

Example fix

// before
PApplet.open(url); // RuntimeException on systems without xdg-open
// after
try {
  PApplet.open(url);
} catch (RuntimeException e) {
  Runtime.getRuntime().exec(new String[]{"firefox", url});
}
Defensive patterns

Strategy: try-catch

Validate before calling

String opener = System.getProperty("os.name").contains("Linux") ? "xdg-open" : "open";
if (Runtime.getRuntime().exec(new String[]{"which", opener}).waitFor() != 0)
  throw new IllegalStateException("No desktop opener installed (e.g. xdg-utils)");

Try / catch

try {
  PApplet.open(target);
} catch (RuntimeException e) {
  logger.warn("open failed, falling back: " + e.getMessage());
  // read stderr: underlying exec error was printed by PApplet.exec
}

Prevention

When it happens

Trigger: Calling PApplet.open(...) / exec(...) when Runtime.exec fails — typically the command does not exist on the platform (e.g. 'xdg-open' missing on Linux, 'open'/'explorer' unavailable), or argv is empty/malformed.

Common situations: Minimal/headless Linux installs without xdg-open; trying to open URLs or files in environments without a desktop; security managers blocking process creation; malformed command arrays with empty elements.


AI-assisted analysis of arduino/Arduino@a0df6e0e83 (2026-09-06). Data as JSON: /api/errors/3b1191a1b6c72bb0. Report an issue: GitHub.