diff options
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 | 90 |
1 files changed, 0 insertions, 90 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 deleted file mode 100644 index 5abbd49d1..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs +++ /dev/null @@ -1,90 +0,0 @@ -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 - { - public enum OutEncoding - { - Default, - Unicode, - } - - private Process _process; - - public String Arguments { get; set; } - - public TimeSpan Timeout { get; set; } - - public String WorkingDir { get; set; } - - public OutEncoding OutputEncoding { 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"; - - if (WorkingDir != null) - { - _process.StartInfo.WorkingDirectory = WorkingDir; - } - - 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) - { - String output = _process.StandardOutput.ReadToEnd(); - String error = _process.StandardError.ReadToEnd(); - - if (OutputEncoding == OutEncoding.Unicode) - { - byte[] data = Encoding.Default.GetBytes(output); - output = Encoding.Unicode.GetString(data); - - data = Encoding.Default.GetBytes(error); - error = Encoding.Unicode.GetString(data); - } - - LogManager.Log($"Process exited with exit code {_process.ExitCode}."); - LogManager.Log($"Process Standard Output:\n{output}"); - LogManager.Log($"Process Standard Error:\n{error}"); - - 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."); - } - }); - } - } -} |
