We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey, I was wondering if its possible to execute a terminal command from a processing sketch. I'm currently working with the carnivore library for processing, which is is a network sniffer. Right now I Need to execute the following code in the terminal (OSX) to give carnivore acces to sniff packages.
sudo chmod 777 / dev / bpf *
However I was wondering If I can run that command from the processing sketch? And how?
Answers
Maybe launch(). Maybe open()... maybe not. Maybe exec(). Yeah, exec() looks good.
https://processing.org/reference/launch_.html (links to java docs, which has:)
exec
public static Process exec(String... args)
Pass a set of arguments directly to the command line. Uses Java's Runtime.exec() method. This is different from the launch() method, which uses the operating system's launcher to open the files. It's always a good idea to use a full path to the executable here.
exec("/usr/bin/say", "-v", "Pipe Organ", "welcome to the command line");
Or if you want to wait until it's completed, something like this:
You can also get the system output and error streams from the Process object, but that's more that we'd like to cover here.
Returns: a Process object
Thx for the answer! I dont really have any experience working with the terminal commands. I tried to run the following code:
exec("/Users/"username/", "sudo chmod 777 / dev / bpf *");
and
exec("sudo chmod 777 / dev / bpf *");
And also:
But processing returns the following error:
Could not open sudo chmod 777 / dev / bpf *.