improved PowerShell scrip host
This commit is contained in:
@@ -9,7 +9,7 @@ namespace mpvnet
|
||||
{
|
||||
public class PowerShellScript
|
||||
{
|
||||
public static object Execute(string filepath, params string[] parameters)
|
||||
public static void Execute(string filepath, params string[] parameters)
|
||||
{
|
||||
using (Runspace runspace = RunspaceFactory.CreateRunspace())
|
||||
{
|
||||
@@ -29,9 +29,7 @@ namespace mpvnet
|
||||
foreach (string i in parameters)
|
||||
pipeline.Commands[1].Parameters.Add(null, i);
|
||||
|
||||
try
|
||||
{
|
||||
var output = new PowerShellOutput();
|
||||
PowerShellOutput output = new PowerShellOutput();
|
||||
output.ModuleName = Path.GetFileName(filepath);
|
||||
|
||||
pipeline.Output.DataReady += output.Output_DataReady;
|
||||
@@ -39,20 +37,23 @@ namespace mpvnet
|
||||
|
||||
runspace.SessionStateProxy.SetVariable("Output", output);
|
||||
|
||||
var ret = pipeline.Invoke();
|
||||
if (ret.Count > 0) return ret[0];
|
||||
try {
|
||||
pipeline.Invoke();
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
Msg.ShowError("PowerShell Exception", e.Message + "\n\n" +
|
||||
e.ErrorRecord.ScriptStackTrace.Replace(" <ScriptBlock>, <No file>", "") +
|
||||
"\n\n" + Path.GetFileName(filepath));
|
||||
}
|
||||
catch (Exception e) {
|
||||
Msg.ShowException(e);
|
||||
}
|
||||
|
||||
pipeline.Output.DataReady -= output.Output_DataReady;
|
||||
pipeline.Error.DataReady -= output.Error_DataReady;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Msg.ShowException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void Init(string filepath)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user