NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Common.IO.ShellCommand Class Reference
Collaboration diagram for Ntp.Common.IO.ShellCommand:

Public Member Functions

 ShellCommand (string command, string arguments, LogBase log, string message)
 
StreamReader Execute ()
 

Properties

string ErrorMessage [get, set]
 
static string WorkingDirectory [get, set]
 

Private Attributes

readonly string arguments
 
readonly string command
 
readonly LogBase log
 

Detailed Description

Definition at line 28 of file ShellCommand.cs.

Constructor & Destructor Documentation

Ntp.Common.IO.ShellCommand.ShellCommand ( string  command,
string  arguments,
LogBase  log,
string  message 
)
inline

Definition at line 30 of file ShellCommand.cs.

31  {
32  this.command = command;
33  this.arguments = arguments;
34  this.log = log;
35  ErrorMessage = message;
36  }
readonly LogBase log
Definition: ShellCommand.cs:41
readonly string arguments
Definition: ShellCommand.cs:38
readonly string command
Definition: ShellCommand.cs:39

Member Function Documentation

StreamReader Ntp.Common.IO.ShellCommand.Execute ( )
inline

Definition at line 46 of file ShellCommand.cs.

References e.

47  {
48  var proc = new global::System.Diagnostics.Process
49  {
50  EnableRaisingEvents = false,
51  StartInfo =
52  {
53  UseShellExecute = false,
54  RedirectStandardOutput = true,
55  RedirectStandardError = true,
57  FileName = command,
58  Arguments = $" {arguments}"
59  }
60  };
61 
62  string error;
63  log.ShellCommandExecuting(command, arguments);
64 
65  try
66  {
67  proc.Start();
68  error = proc.StandardError.ReadToEnd().Replace(Environment.NewLine, " ");
69  proc.WaitForExit();
70  }
71  catch (Exception e)
72  {
73  log.WriteLine(e.Message, Severity.Warn);
74  throw;
75  }
76 
77  if (error == string.Empty)
78  return proc.StandardOutput;
79 
80  log.ShellCommandError(ErrorMessage, error);
81  return null;
82  }
abstract void WriteLine(string text, Severity severity)
readonly LogBase log
Definition: ShellCommand.cs:41
static string WorkingDirectory
Definition: ShellCommand.cs:42
var e
Definition: bootstrap.min.js:6
readonly string arguments
Definition: ShellCommand.cs:38
readonly string command
Definition: ShellCommand.cs:39

Member Data Documentation

readonly string Ntp.Common.IO.ShellCommand.arguments
private

Definition at line 38 of file ShellCommand.cs.

readonly string Ntp.Common.IO.ShellCommand.command
private

Definition at line 39 of file ShellCommand.cs.

readonly LogBase Ntp.Common.IO.ShellCommand.log
private

Definition at line 41 of file ShellCommand.cs.

Property Documentation

string Ntp.Common.IO.ShellCommand.ErrorMessage
getset

Definition at line 44 of file ShellCommand.cs.

string Ntp.Common.IO.ShellCommand.WorkingDirectory
staticgetset

Definition at line 42 of file ShellCommand.cs.

Referenced by Ntp.Analyzer.Cli.Program.Main().


The documentation for this class was generated from the following file: