more G-Labs products

Author Topic: How to call a Shell Script from HG  (Read 929 times)

January 20, 2016, 10:50:54 PM
Read 929 times

HGexperimenter

  • **
  • Information
  • Jr. Member
  • Posts: 42
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");



« Last Edit: January 20, 2016, 11:56:29 PM by HGexperimenter »


There are no comments for this topic. Do you want to be the first?