This reference is for Processing 2.0+. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.

Name

open()

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

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

void mousePressed() {
  println("Opening Process_4");
  open("/Applications/Process_4.app");
}


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

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

void mousePressed() {
  String[] params = { "/usr/bin/jikes", "-help" };
  open(params);
}

Description Attempts to open an application or file using your platform's launcher. The filename parameter is a String specifying the file name and location. The location parameter must be a full path name, or the name of an executable in the system's PATH. In most cases, using a full path is the best option, rather than relying on the system PATH. Be sure to make the file executable before attempting to open it (chmod +x).

The argv parameter is a String or String array which is passed to the command line. If you have multiple parameters, e.g. an application and a document, or a command with multiple switches, use the version that takes a String array, and place each individual item in a separate element.

If argv is a String (not an array), then it can only be a single file or application with no parameters. It's not the same as executing that String using a shell. For instance, open("jikes -help") will not work properly.

This function behaves differently on each platform. On Windows, the parameters are sent to the Windows shell via "cmd /c". On Mac OS X, the "open" command is used (type "man open" in Terminal.app for documentation). On Linux, it first tries gnome-open, then kde-open, but if neither are available, it sends the command to the shell without any alterations.

For users familiar with Java, this is not quite the same as Runtime.exec(), because the launcher command is prepended. Instead, the exec(String[]) function is a shortcut for Runtime.getRuntime.exec(String[]).
Syntax
open(filename)
open(argv)
Parameters
filename String: name of the file
argv String[]: list of commands passed to the command line
Returnsvoid or Process
Updated on March 27, 2014 07:26:05pm EDT

Creative Commons License