diff options
| author | Avi Levkovich <avi@twine-s.com> | 2018-12-12 10:55:01 +0200 |
|---|---|---|
| committer | Avi Levkovich <avi@twine-s.com> | 2018-12-12 10:55:01 +0200 |
| commit | 4b7119fd239e1c52c5f82d4a44e9368c31c718b2 (patch) | |
| tree | 3fb640fd6092288d31dc207432e01982d72413b7 /Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs | |
| parent | a843fbdbc0cd9cb9b6f9f753a64127b15e74c47c (diff) | |
| parent | 7427f44de312fb00e138320cedd7d4459015910a (diff) | |
| download | Tango-4b7119fd239e1c52c5f82d4a44e9368c31c718b2.tar.gz Tango-4b7119fd239e1c52c5f82d4a44e9368c31c718b2.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/_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.cs | 60 |
1 files changed, 60 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..2ee0d83d9 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs @@ -0,0 +1,60 @@ +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; + 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."); + } + }); + } + } +} |
