Script run from sketch is not exiting

I am calling a script called ‘pi_camera_script’ to take a picture using the RPi camera and then upload it to dropbox. I have followed the example of the pi camera project and have tested the script on the Pi through the command terminal. This all works fine.

When I call the script from my sketch:

Serial.println("5 minutes passed - take photo and upload");
Process proc = Process::run("/home/pi/bin/pi_camera_script"); // image capture and upload shell script
proc.wait();
Serial.println("Done!");

It never exits.

If I monitor the serial outputs it just appears to freeze after the picture has been taken and on the dropbox_uploader

The script is like this

#!/bin/bash
DATE=$(date +"%Y-%m-%dT%H%M%S")
raspistill -vf -hf /home/pi/piCam/$DATE.jpg
/usr/local/dropbox_uploader upload /home/pi/piCam/$DATE.jpg "Pi_Camera/"

I am wondering if this is something to do with permissions on the dropbox_loader? Help appreciated.

Try testing the script on the command line with ./pi_camera_script and see what happens.

1 Like

@kennethlimcp The script is in /home/pi/bin so ./pi_camera_script from the command line doesn’t work but /home/pi/bin/pi_camera_script does work fine.

The issue is still the script gets called by the sketch the still picture is taken and stored but the dropbox_uploader hangs and indeed so does the sketch I am guessing waiting for the process to exit?

Does the script, when run on the command line exit fine?

Yes, I have put some echo outputs and there is an output from the dropbox_uploader.

@jvanier might have some idea why it’s not exiting

Try adding proc.in().close(); before proc.wait(). Maybe the Dropbox upload script is reading the standard input and waiting forever for the firmware to send some input.

Here are the docs for Process.in()

@jvanier I have got around to trying this and unfortunately it doesn’t make any difference. To recap the issue, the script runs fine when run from the console (takes a picture, stores it in the piCam directory and then uploads to dropbox). When called from the Process::run() the script takes a picture, stores the image and then seemingly skips the dropbox_uploader. The dropbox_uploader does output to the console, > Uploading "xyz" to "/dropbox"... DONE so I am now wondering if this is the problem when the script is run from the Process::run()? Should I be using proc.out() to read this output? I have tried dropbox_uploader -q upload to invoke quiet mode, this doesn’t seem to do anything different.