Clary:
I try to put the script in various directories and it works.
I think you misunderstood me, I must not have been clear. I wasn't suggesting that you move the script to various directories. Keep the script in your desired directory, and then change to other directories and try running the script. For example, if the script is in /mnt/sda1/capture/capture-image.py
, go to a different directory and try running it from there while the script is still in the original directory. For example, "cd /
" followed by "python /mnt/sda1/capture/capture-image.py
"
The key is that when you run a script from a Process object, you cannot make assumptions about what the current directory will be when it runs the script. The script must be written so that it can be RUN from any directory, where that directory is NOT the directory that contains the script.
The script is in the same directory of the sketch
This is meaningless. The sketch is loaded into the flash memory of the Yun's '32U4 processor, and has no correlation to the file system on the Linux side. You may have a copy of the sketch somewhere on the Linux side of the Yun, but that has no significance at all. And it certainly doesn't mean that any directory that happens to include a copy of the sketch will be the current directory when a Process object tries to access any files.
p.begin("python");
p.addParameters("capture-image.py");
p.run();
This won't work. It will attempt to run the capture-image.py script from whatever directory the Process object is using as its default directory. Odds are that you have not placed a copy of the script in that directory. In my experience you must use a full path to your script file, or the Process object will not be able to find it. For example:
p.begin("python");
p.addParameters("/mnt/sda1/capture/capture-image.py");
p.run();
Another thing that may be helpful, at least during development, is to echo any output you get from the Process object to the Serial port (or Console if you are working over a network connection.) That way, if the Process object returns any error messages, you can see what they are. My guess is that it is returning a message that it can't find capture-image.py.
Take a look at the Bridge Library Process Tutorial for an example of getting the output from the Process object and sending it to the Serial port. This is the interesting bit of code that you could call after p.run():
while (p.available()>0) {
char c = p.read();
Serial.print(c);
}
Serial.flush();
Of course, you will also need to set up the Serial port in the setup() function. Or, if you are using a network connection, you would want to use the Console class instead of the Serial class.