We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Execute Terminal commands
Page Index Toggle Pages: 1
Execute Terminal commands (Read 1363 times)
Execute Terminal commands
Mar 16th, 2009, 12:54pm
 
Hi guys,
i tried to execute commands (like opening the cd drive) from the terminal (Mac OSX 10.5.6) which works, now i would like write a processing app which does the same. But i cant figure out how to do that. i tried the open() command like this:

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

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

void mousePressed() {
 String[] params = { "cd ../", "info" };
 open(params);
}

but this doesn't work ????
Re: Execute Terminal commands
Reply #1 - Mar 16th, 2009, 1:39pm
 
Mmm, I am not familiar with OSX, but this seems fishy...
The first index of params is supposed to hold the (path to) the exe to run. Here, you provide a command with an argument. The arguments are supposed to be on the second and next params.
Re: Execute Terminal commands
Reply #2 - Mar 16th, 2009, 2:42pm
 
it still doesn't work. I have it now like this:

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

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

void mousePressed() {
 String[] params = { "../", "drutil tray eject disk0s2" };
 open(params);
}
Re: Execute Terminal commands
Reply #3 - Mar 16th, 2009, 4:08pm
 
"../" isn't a command/exe file.
What is the command you type on the command line?
Out of guess, I think your init should look like:
String[] params = { "drutil", "tray", "eject", "disk0s2" };
Re: Execute Terminal commands
Reply #4 - Mar 16th, 2009, 4:37pm
 
thats not working either.
the command is "drutil tray open disk0s1" its not working as a string nor as an array out of the single words:

void mousePressed() {
 String[] params = {"drutil", "tray", "open", "disk0s1"};
 open(params);
//  open("/Applications/TextEdit.app");
 println("OPEN");
}


someone ever tried this?
Re: Execute Terminal commands
Reply #5 - Mar 16th, 2009, 5:21pm
 
Well, I am unclear of the difference between open() and exec() on Mac OS. Have you tried the latter?

Perhaps somebody with a Mac might help you better than me.
Re: Execute Terminal commands
Reply #6 - Mar 16th, 2009, 5:22pm
 
I haven't used 'open' but I have run an external program with Runtime.getRuntime().exec().
In this case, I opened notepad.

The command that you would type into the console would be all in one string (i.e. "drive\\pathto\\exe argument")

Keep in mind this was run in Windows only.


Code:

import java.io.*;


try {

Process p = Runtime.getRuntime().exec("C:\\windows\\notepad.exe");

} catch (Exception err) {
err.printStackTrace();
}

exit();

Re: Execute Terminal commands
Reply #7 - Mar 16th, 2009, 5:50pm
 
the before code from me works as well to open applications, but somehow the command line commands dont work?
Re: Execute Terminal commands
Reply #8 - Mar 16th, 2009, 7:27pm
 
Is the command you are sending an application or functions only within the console?

If they are functions of the console, are you able to open() or exec() the console application with your commands as arguments?

Possibly exec a script file(like a *.bat in windows)

(sorry not familiar with Mac OS either)
Re: Execute Terminal commands
Reply #9 - Mar 17th, 2009, 12:40pm
 
Yes its a command to open the cd tray.
It works when entering to the Terminal: drutil tray eject disk0s2

But I can't make it execute from processing.
Re: Execute Terminal commands
Reply #10 - Mar 17th, 2009, 12:45pm
 
ok i got it, it works like this on Mac:

void mousePressed() {
 String[] params = {"drutil", "tray", "eject","disk0s2" };
 exec(params);
}

thanks for your help!
Page Index Toggle Pages: 1