Go Down

Topic: MOVED TO YUN: Process.runShellCommand - Shell program executed repeatedly (Read 1 time) previous topic - next topic


Hi all --

A shell program that I'm executing with runShellCommand(...) seems to run repeatedly, rather than run once.

Code: [Select]

#include <Process.h>

void setup() {
 Bridge.begin();   // Initialize the Bridge
 Serial.begin(9600);   // Initialize the Serial

 Process p;


 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:
Code: [Select]

while [ 1 ] ;
       touch test$INCR
       sleep 1
       rm test$INCR

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
Code: [Select]

proc = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE)

is being invoked. But opening up python in that directory and running
Code: [Select]

>>> 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`:
Code: [Select]

__future__ import print_function

class Processes:
 def __init__(self):
   self.processes = { }
   self.next_id = 0
 def create(self, cmd):
   # Start the background process
     f = open('writing_cmd', 'a')
     print(cmd, file=f)
     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?


the shell script you created runs in an endless loop.
Is that what you wanted?
You should explain what you want to do.


Go Up