I know this thread is a bit old, but it was the first result when searching the site for "command line" so I figured I'd share what I just found out.
You don't need to override main() -- or anything for that matter -- to get the command line parameters (your parsing code is a bit overcomplicated as well). Processing already parses them and provides them to the sketch via PApplet.args (the "args" variable, as you'd reference it in your sketch), e.g. if you wanted to load them into a Properties (or a Map or any container you want), all you need to do is:
- Properties loadCommandLine () {
- Properties props = new Properties();
-
- for (String arg:args) {
- String[] parsed = arg.split("=", 2);
- if (parsed.length == 2)
- props.setProperty(parsed[0], parsed[1]);
- }
-
- return props;
- }
- void setup () {
-
- Properties props = loadCommandLine();
-
- size(400, 200);
- background(0);
- text(props.toString(), 10, 20);
- text(props.getProperty("text", "No 'text' parameter set."), 10, 40);
- }
Usage e.g.:
- $ ./sketch_121017a.exe a=b "text=Hello there."
Yields:
P.S. Don't override loop(), that's not what loop() is for. The loop() functions resumes the draw() loop after noLoop() is called, it's not a function that's called repeatedly by processing. See
http://processing.org/reference/loop_.html.
Jason