Run code from terminal [Linux]

Hi,

is it possible to run code directly in the terminal?

Something like this:
:~$ processing> size(400, 400); rect(120, 80, 50, 50);

I read in a previous post that I need to install “processing-java”, but I can’t find it.
[I use Processing 4.3 on Linux, gnome-terminal 3.44.0]

Thank you,
f

This is in the Wiki in the Processing 3.5.4 repository:

I did not see it here:

Give it a try and share your experience.

:)

Thank you.
I had already seen the first link, but I didn’t understand where I should download “processing-java” for Linux.
Then…I realized it’s in the Processing download folder: in fact it is present and it works.
I can run a sketch directly in the terminal by specifying the folder and file name, and it works fine.
But…what I would like to do is run the code by writing it directly in the terminal, not execute a file. I wasn’t able to do this and I don’t understand if it can be done.

Bye,
f

I’m not sure that you can achieve what you want to do with Processing source code, but you might be able to do it with java code. I’ve also seen it done with objc on a Mac. Reference: https://docs.groupdocs.com/viewer/java/how-to-create-minimal-java-app/

This is example code that runs on a mac; you’ll have to try it on Linux:

echo 'public class App {
    public static void main(String[] args) {
      System.out.println("Hello, World!");
    }
}
' > App.java | javac -d . App.java | java -classpath . App

Thank you,
it works fine on Linux:

x@x:~$ echo 'public class App {
    public static void main(String[] args) {
      System.out.println("Hello, World!");
    }
}
' > App.java | javac -d . App.java | java -classpath . App
Hello, World!
x@x:~$

So, how should I use it to run, for example, this simple code below directly in the linux terminal?

size (600, 600);
strokeWeight(10);
point(300, 200);
strokeWeight(1);

Thank you,
f

2 Likes

You need to continue to use processing-java, using this procedure:

  1. Create a folder with the same name as the sketch (eg, testSketch)
  2. In Terminal change to that directory.
  3. Copy/paste this code:
echo 'size (600, 600);
strokeWeight(10);
point(300, 200);
strokeWeight(1);' > testSketch.pde | processing-java --sketch=/Users/yourName/testSketch --run

The code that you enter on the command line will be redirected to your sketch file, and then it will be run by processing-java after entering the name of its folder. This was done on a mac; you will have to test it on Linux.

Hit return and you should see this output:

1 Like

This worked on W10 command-line:

d:\test>echo size(530,530);for(int j=0,m=23,r=0;j^^^<m*m;r=choice(2)*m)line(j%m*m+r,j/m*m,j%m*m+m-r,j++/m*m+m); > test.pde | processing-java --sketch=d:\test --run

I had to create a folder d:\test

See here for the ^^^:
Quotes, Escape Characters, Delimiters - Windows CMD - SS64.com

Output:

:)