aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-12-18 17:59:41 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-12-18 17:59:41 +0200
commitf131b2573bfb617998927ea1072eb946b800d5e7 (patch)
tree949b9cc7b7248abd958d7b5300dd2082495acbd7 /Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs
parent45ac8eaf0e03d87c2f9728b2b7c84922c6f6a37d (diff)
downloadTango-f131b2573bfb617998927ea1072eb946b800d5e7.tar.gz
Tango-f131b2573bfb617998927ea1072eb946b800d5e7.zip
PPC working on tablet !
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.cs33
1 files changed, 31 insertions, 2 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
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}.");