Hi all --
A shell program that I'm executing with runShellCommand(...) seems to run repeatedly, rather than run once.
#include <Process.h>
void setup() {
Bridge.begin(); // Initialize the Bridge
Serial.begin(9600); // Initialize the Serial
Process p;
p.runShellCommand("/root/shell_example.sh");
while (p.running());
while (p.available()) {
}
delay(5000); // wait 5 seconds before you do it again
}
void loop(){}
On the linino, we have this file in /root called shell_example.sh:
#!/bin/sh
INCR=0
while [ 1 ] ;
do
touch test$INCR
sleep 1
rm test$INCR
INCR=$((INCR+1))
done
This file just creates a file named testi every second, and increments i, e.g. test0, test1, test2, test3, ...
When I run the Arduino code, a file named test0 is created every second, in /usr/lib/python2.7/bridge
(where bridge.py exists), as if the shell_example.sh
was being called every second.
So what's going on with the runShellComand? Does it repeatedly call the command?
In processes.py in /usr/lib/python2.7/bridge, I'm assuming that command
proc = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE)
is being invoked. But opening up python in that directory and running
>>> from subprocess import Popen
>>> Popen('/root/shell_example.sh')
<subprocess.Popen object at 0x77bf05f0>
does the right thing: test0, test1, test2, ... get created.
So, I'm assuming that the cmd
is being garbled somehow. I tried to write the command to a file by modifying the source of processes.py
:
__future__ import print_function
class Processes:
def __init__(self):
self.processes = { }
self.next_id = 0
def create(self, cmd):
# Start the background process
try:
f = open('writing_cmd', 'a')
print(cmd, file=f)
f.close()
proc = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE)
But no file was written.
Any ideas why this shell program isn't being executed correctly?