HomeGenie Forum

Automation Program Plugins and Wizard Scripting => APP Contributions => Topic started by: HGexperimenter on January 20, 2016, 10:50:54 PM

Title: How to call a Shell Script from HG
Post by: HGexperimenter on January 20, 2016, 10:50:54 PM
To save others some time, here's how to call a shell script from HG:
(in my case it calls a shell that creates a text file with the weather and then a .wav file from the text)
Notes: Full path required to the shell command file, the "user" is "pi"


Code: [Select]
//Startup:
Program.UseWidget("homegenie/generic/program");
//Program:
Program.Notify("weatherCreateWav: ", "start");
var proc = new System.Diagnostics.Process {
StartInfo = new System.Diagnostics.ProcessStartInfo {
FileName = "sh",
Arguments = "/home/pi/sh/weatherTTS.sh",
UseShellExecute = false,
RedirectStandardOutput = true,
} // end ProcessStartInfo
}; //end Process

// This gets the data if something returned (i.e. "echo xxxx")
proc.Start();
while (!proc.StandardOutput.EndOfStream) {
string line = proc.StandardOutput.ReadLine();
Program.Notify("weatherCreateWav: Stream output:", line);
Pause(1);
} // end while EndOfStream
Program.Notify("weatherCreateWav: ", "complete");