From f131b2573bfb617998927ea1072eb946b800d5e7 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 18 Dec 2018 17:59:41 +0200 Subject: PPC working on tablet ! --- .../PPC/Tango.PPC.Common/Scripting/CmdCommand.cs | 33 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs index abae98f06..5abbd49d1 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs @@ -11,12 +11,22 @@ 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); @@ -30,6 +40,12 @@ namespace Tango.PPC.Common.Scripting _process.StartInfo.RedirectStandardOutput = true; _process.StartInfo.Arguments = arguments; _process.StartInfo.Verb = "runas"; + + if (WorkingDir != null) + { + _process.StartInfo.WorkingDirectory = WorkingDir; + } + Arguments = arguments; } @@ -43,9 +59,22 @@ namespace Tango.PPC.Common.Scripting 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{_process.StandardOutput.ReadToEnd()}"); - LogManager.Log($"Process Standard Error:\n{_process.StandardError.ReadToEnd()}"); + 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}."); -- cgit v1.3.1