aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2018-12-12 18:47:31 +0200
committerShlomo Hecht <shlomo@twine-s.com>2018-12-12 18:47:31 +0200
commitf901d520c6a62797eae912144d6c33d5881cc272 (patch)
tree76ab476634f2b443a41e8b4f1180d2164f8aceed /Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs
parent33de2cfe94b9fde80f987aab9ad5aa95be6d4371 (diff)
parentd9a89773f2f283fbf5596799dd4d50d231817203 (diff)
downloadTango-f901d520c6a62797eae912144d6c33d5881cc272.tar.gz
Tango-f901d520c6a62797eae912144d6c33d5881cc272.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs61
1 files changed, 61 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs
new file mode 100644
index 000000000..abae98f06
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs
@@ -0,0 +1,61 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core;
+
+namespace Tango.PPC.Common.Scripting
+{
+ public class CmdCommand : ExtendedObject
+ {
+ private Process _process;
+
+ public String Arguments { get; set; }
+
+ public TimeSpan Timeout { get; set; }
+
+ public CmdCommand(String processName, String arguments)
+ {
+ Timeout = TimeSpan.FromSeconds(5);
+
+ _process = new Process();
+ _process.StartInfo.CreateNoWindow = true;
+ _process.StartInfo.FileName = processName;
+ _process.StartInfo.UseShellExecute = false;
+ _process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
+ _process.StartInfo.RedirectStandardError = true;
+ _process.StartInfo.RedirectStandardOutput = true;
+ _process.StartInfo.Arguments = arguments;
+ _process.StartInfo.Verb = "runas";
+ Arguments = arguments;
+ }
+
+ public Task Run()
+ {
+ return Task.Factory.StartNew(() =>
+ {
+ LogManager.Log($"Starting process {_process.StartInfo.FileName} with arguments {Arguments}...");
+ _process.Start();
+ _process.WaitForExit((int)Timeout.TotalMilliseconds);
+
+ if (_process.HasExited)
+ {
+ LogManager.Log($"Process exited with exit code {_process.ExitCode}.");
+ LogManager.Log($"Process Standard Output:\n{_process.StandardOutput.ReadToEnd()}");
+ LogManager.Log($"Process Standard Error:\n{_process.StandardError.ReadToEnd()}");
+ if (_process.ExitCode != 0)
+ {
+ throw new IOException($"The process {_process.StartInfo.FileName} has exited with the code {_process.ExitCode}.");
+ }
+ }
+ else
+ {
+ throw new TimeoutException($"The process {_process.StartInfo.FileName} has not exited within the given timeout of {Timeout.TotalSeconds} seconds.");
+ }
+ });
+ }
+ }
+}