Added Process.runShellCommand*() methods.
This commit is contained in:
parent
8674a1b9e9
commit
406c20222a
|
@ -118,6 +118,20 @@ void Process::close() {
|
||||||
started = false;
|
started = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int Process::runShellCommand(const String &command) {
|
||||||
|
runShellCommandAsynchronously(command);
|
||||||
|
while (running())
|
||||||
|
delay(100);
|
||||||
|
return exitValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Process::runShellCommandAsynchronously(const String &command) {
|
||||||
|
begin("/bin/ash");
|
||||||
|
addParameter("-c");
|
||||||
|
addParameter(command);
|
||||||
|
runAsynchronously();
|
||||||
|
}
|
||||||
|
|
||||||
// This method is currently unused
|
// This method is currently unused
|
||||||
//static unsigned int __commandOutputAvailable(uint8_t handle) {
|
//static unsigned int __commandOutputAvailable(uint8_t handle) {
|
||||||
// uint8_t cmd[] = {'o', handle};
|
// uint8_t cmd[] = {'o', handle};
|
||||||
|
|
|
@ -36,6 +36,9 @@ public:
|
||||||
unsigned int exitValue();
|
unsigned int exitValue();
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
|
unsigned int runShellCommand(const String &command);
|
||||||
|
void runShellCommandAsynchronously(const String &command);
|
||||||
|
|
||||||
operator bool () { return started; }
|
operator bool () { return started; }
|
||||||
|
|
||||||
// Stream methods
|
// Stream methods
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
/* Demonstrate shell commands */
|
||||||
|
|
||||||
|
#include <Process.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Bridge.begin();
|
||||||
|
Console.begin();
|
||||||
|
Console.buffer(64);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
Process p;
|
||||||
|
// This command line prints the number of bytes received and transmitted from WLAN
|
||||||
|
p.runShellCommand(F("ifconfig wlan0 | grep \"RX bytes\" | tr ':' ' ' | awk \"{ print \\$3 \\\" \\\" \\$8 }\"\n"));
|
||||||
|
|
||||||
|
// Read command output
|
||||||
|
while (p.available()) {
|
||||||
|
char c = p.read();
|
||||||
|
Console.print(c);
|
||||||
|
}
|
||||||
|
Console.flush();
|
||||||
|
|
||||||
|
delay(5000);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue