Running python script

Hello:

I’m trying to download an image from S3 and save it to SD card using Boto library. Here is my python script, download.py

from boto.s3.connection import S3Connection
print ‘script begins’
conn = S3Connection(‘AMAZON_ACCESS_KEY’, ‘AMAZON_SECRET_KEY’)
b = conn.get_bucket(‘BUCKET_NAME’) # substitute your bucket name here

from boto.s3.key import Key
k = Key(b)
k.key = ‘samplesound.caf’
k.get_contents_to_filename(‘sampleimage.jpg’)
print ‘script ends’

When I run the script above directly from ssh by typing python download.py, the file is downloaded from S3 and saved to sd card. However, when I run it from sketch like the follow, the python script executes (since it prints debug string within the script), but the file is never saved.

#include <Bridge.h>
#include <Process.h>
#include <Console.h>

void setup() {

}

void loop() {

}

void downloadFromS3 {
Console.println(“Download S3 begins!”);
digitalWrite(13, HIGH);
Process p;
p.begin(“python”);
p.addParameter("/mnt/sda1/arduino/download.py");
p.run();

while (p.available()) {
char c = p.read();
Console.print(c);
}

}

Can anyone tell me why?

I appreciate any feedback in advance. Thank you.

Change to absolute path:

k.get_contents_to_filename('sampleimage.jpg')
k.get_contents_to_filename('/mnt/sda1/sampleimage.jpg')

Absolute path & relative path

Thank you so much. It seems to work! :slight_smile:

As a bit of explanation: when you run the script manually from an SSH connection, you have switched to a directory, and the script is running from that current directory. When it goes to save a file that has no path information,MIT puts it in the current directory. Since you are there, you find the file.

But when you run it from the Process object, you are not running from the same directory. Instead, the current directory is buried down in the system tree. The file is still being created, but not in the directory you expect, so you can't find it and you think the operation has failed.