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.
Page Index Toggle Pages: 1
System Commands (Read 1009 times)
System Commands
Nov 11th, 2009, 2:53pm
 
Hi There

Does anyone know if there is a way to run system commands in processing like os in python.

I have tried using open() but as the name suggest it only seem to open programs or files

here a example of what i am trying to do

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

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

void mousePressed() {
 open("echo info > /Test.txt");
}


Cheers

James
Re: System Commands
Reply #1 - Nov 12th, 2009, 1:59am
 
Well, you know what? As I expected, your sketch just works!
But as you didn't expect, it writes the file at the root of C: (on my Windows system).
Why? Processing creates the sketches in the temp dir of your system, which is located, for me, on C:, somewhere in my user directory. It runs them from there, so current dir is this temp dir. You write on the root of the disk (the /Test.txt path), so data went there.
Re: System Commands
Reply #2 - Nov 12th, 2009, 5:42am
 
Hi Phil

Thanks for Replying

Thats strange maybe there's a difference between the Mac and PC

as i have tried with a full path and it still doesn't work

Code:

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

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

void mousePressed() {
 println("Opening Process_4");
 open("echo info >/Users/james/Desktop/test_001.txt");
}


My main aim is to run a script but it justs opens the text file up instead, any suggestions

Cheers

James
Re: System Commands
Reply #3 - Nov 12th, 2009, 8:13am
 
Hi James,

On the Mac, open() does the equivalent of what would happen if you double-clicked on the file you specified, which may be why your script is opening in an editor instead.  If you are using something like AppleScript, you should save the file as an Application using the AppleScript Editor.  Check that double-clicking will run rather than open the file and then try again.

Re-read the documentation for the open() command and "man open" on the Mac closely for details on the platform-specific differences:

 http://processing.org/reference/open_.html

If you have an actual shell script rather than an AppleScript, then you might try the exec(String[]) command mentioned above.

I hope this helps!

-Matt
Re: System Commands
Reply #4 - Nov 12th, 2009, 8:14am
 
OK maybe I'm showing my ignorance of Macs but that still looks like a relative path:

/Users/james/Desktop/test_001.txt

Surely that's still relative to 'root' which, as PhilHo suggested, your program will presumably interpret as running from its root, not your system root...

On a PC a full path would start with a drive letter:

C:/etc...
Re: System Commands
Reply #5 - Nov 12th, 2009, 8:34am
 
blindfish, on Unix systems (that's what MacOS is, now), a path starting with slash is an absolute path. Well, that's also the definition of a path relative to the root dir... Smiley (system root, I know no other, actually).

Actually, this also applies to Windows systems as well: foo/bar (or foo\bar, that's the same on XP and above) is a relative path, /foo/bar is an absolute path (or actually relative to root of current drive).
Re: System Commands
Reply #6 - Nov 12th, 2009, 8:43am
 
Ah - OK...  I'm applying my experience of a different environment where it's not relevant: I've used one authoring tool which treats '/' as the root directory of the application rather than system root.  That and my brain hurts today  Undecided
Re: System Commands
Reply #7 - Nov 12th, 2009, 3:07pm
 
Hi Matt

The exec() was exactly what i was after.

Many Thanks

James
Page Index Toggle Pages: 1