How to send an argument when using processing-java

I can run a Processing sketch from the command line using
processing-java --sketch=pathtosketchfolder --run
But, how do I send an argument, such as the value of a variable, at the same time?

I have no experience doing this but found the following when ‘processing-java‘ was typed into Terminal on MacOS:

The --build, --run, --present, or --export must be the final parameter
passed to Processing. Arguments passed following one of those four will
be passed through to the sketch itself, and therefore available to the
sketch via the 'args' field. To pass options understood by PApplet.main(),
write a custom main() method so that the preprocessor does not add one.

Hello @paulstgeorge,

What version of Processing and OS are you using?

I use processing cli with Processing 4.4.10 and W10.

processing-java
is now replaced with
processing cli

See this reference for processing-java.exe :
https://github.com/processing/processing/wiki/Command-Line#adding-command-line-arguments

References:
Processing 4 processing-java binary? - #10 by stefterv
processing cli --help links to old repository · Issue #1366 · processing/processing4 · GitHub

:)

That, plus the code from Command Line · processing/processing Wiki · GitHub worked perfectly, thanks.
I had trouble using settings(), so put the extra code in setup()

Hello and happy new year @glv
I am using Processing 4.4.7 and Mac OS
I have looked at Environment / Processing.org

But I still need more help with the syntax of the commands, and with the code to add to the sketch (please)…

Hello @paulstgeorge,

And Happy New Year!

Hopefully something here can help.
Keep in mind that there are differences between W10 and macOS.

See:
CLI: `--help` not working on Windows 10/11 · Issue #1306 · processing/processing4 · GitHub

W10 command-line:

D:\>processing cli --sketch="D:\Users\GLV\Documents\P4\cli_args_1_0_0" --run test 123 3.1415927

This works for Processing 4.4.10 and W10:

// This is what I used for Windows 10 Processing 4.4.10:
// D:\>processing cli --sketch="D:\Users\GLV\Documents\P4\cli_args_1_0_0" --run test 123 3.1415927
  
void setup()
  {
  size(300, 300);
  background(255, 255, 0);
  fill(0);
  textSize(24); 
  
  // For testing only since you don't have a console for errors in this example
  //String args [] = {"test", "123", "3.141592"}; 
  
  if (args != null) 
    {
    background(0, 255, 0);
    fill(0);
    textSize(24);
    String s = "Arguments passed: " + args.length + '\n';
    for(int i = 0; i<args.length; i++)
      {
      s = s+ args[i] + '\n';  
      }
    text(s, 20, 20, width-20, height-20);  
    }
  noLoop();  
  }

processing-java < Try this in place of this for your environment:
processing cli

I do not have Processing 4.4.7 and a macOS to test this on and using Processing 4.4.10.

Can you try this with version 4.4.7 and 4.4.10 on your macOS?
processing cli may work with Processing 4.4.7… give it a try!

Be mindful of folder you are working from:
Environment / Processing.org
Alternate Processing Editor Using processing-java.exe on the Command line - #8 by svan

:)

Thanks,

I understand the command line and I understand the code used in setup(), but I don’t understand this:

processing-java.exe < Try this in place of this for your environment:
processing cli

Do I need to download and/or install something and then put it in the correct place?

On MacOS there are currently a couple of ways that you can use the command line to run a Processing sketch and you are being asked to try the alternate method. Currently you are using processing-java which requires a Terminal command which looks like this:

% processing-java –-sketch=path/to/your/sketchFolder –-run your argument

What you are being asked to try is to access Processing.exe in the app bundle and then launch cli from there, which means that you need two lines of code instead of one:

% cd /Applications/Processing.app/Contents/MacOS

then a second command to launch the Processing executable

% ./Processing cli --sketch=path/to/your/sketchFolder --run your argument

For Mac users the first is pretty simple; however, the other platforms use different methods and don’t have this option. As of v.4.4.10 we still have the option to install processing-java from the Tools menubar item:

If that option were to be taken away in the future, Mac users would be forced to use processing cli from the Processing.app bundle. If you don’t already know, you can do a right click on your Processing.app and see the contents of the bundle. If you look in the Contents/MacOS folders you should see the main Processing.exe file that you are being asked to try. On the other hand, processing-java is a small 4k executable file which lives at /usr/local/bin on my system. I think that it likely gets installed there when the menu item is selected.

3 Likes

@svan
Excellent. That all makes sense, and works perfectly. And I have two ways to use the command line. This could be useful if one of the options is removed.

1 Like

You were already using processing-java (initial post) and I was using processing cli examples and suggesting to try it in my examples.

I see that this is all sorted out!

I shared my feedback in this issue:

:)