private void Execute(string cmd)
{
if (String.IsNullOrEmpty(cmd))
{
return;
}
Log.InfoFormat("Executing command: {0}", cmd);
using (var powerShell = PowerShell.Create())
{
powerShell.Runspace = _runspace;
powerShell.AddScript(cmd);
// Add the default outputter to the end of the pipe and then
// call the MergeMyResults method to merge the output and
// error streams from the pipeline. This will result in the
// output being written using the PSHost and PSHostUserInterface
// classes instead of returning objects to the host application.
powerShell.AddCommand("out-default");
powerShell.Commands.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
powerShell.Invoke();
}
if (_timer != null)
{
_timer.Dispose();
}
_timer = new Timer(x => _exitCallback(), null, TimeSpan.FromMinutes(5), TimeSpan.FromMilliseconds(-1));
}