Loading...
Logo
Processing Forum

Hi there, having a bit of an issue with a sketch I'm working on at the moment. I'm currently trying to get Processing to call Terminal to read a txt file and execute its contents. Ideally, Terminal would write the resultant data to another txt file, which my Processing sketch could then access.

I found these lines of code on an old forum post:


void mousePressed() {

 String[] params = {"drutil", "tray", "eject","disk0s2" };

 exec(params);

}


While near the mark, the same format doesn't seem to apply to reading and executing a txt file:


void mousePressed() {

String [] params = {"source", "parserrun.txt"} ;

 println(params);

 exec(params);

}



More info here:

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

http://processing.org/discourse/beta/num_1237204442.html


In the disk example they use exec, but it appears there's a difference between using exec and open that I'm not aware of.

The documentation says: "For users familiar with Java, this is not quite the same as Runtime.exec(), because the launcher command is prepended. Instead, the exec(String[]) function is a shortcut for Runtime.getRuntime.exec(String[]). "


I'd greatly appreciate any advice. Cheers.

Replies(2)

open() does the right thing depending on the platform. Eg. on Windows, it prepends "cmd", "/c" to the command.
With exec(), you have to do that yourself.
I am struggling with the same problem. I also saw the example for ejecting a disk, but when I try other commands it doesn't work. (neither with open() as with exec())

The thing I want to do is send a document to a printer. I'm working on mac osx and I want to use the following commandline:  lp -d printername documentpath . The command does work in my terminal so that is not the problem.

In my processing script I tried it like this:
Copy code
  1. void mousePressed() {
  2.  String[] params = {"lp", "-d", "printername", "documentpath"};
  3.  exec(params);
  4. }
Can someone solve this problem or?
Thanks in advance!