/// <inheritdoc /> public IEnumerable <IPAddress> GetRespondingMachines() { var arpScanResults = new List <IPAddress>(); using (IProcessWrapper arpScanProcess = getArpScanProc()) { arpScanProcess.Start(); string procOut = ""; while ((procOut = arpScanProcess.StandardOuput.ReadLine()) != null) { string[] parts = procOut.Trim().Split(' '); if (parts.Length < 2 || parts[parts.Length - 1] == "invalid") { continue; } // end if string address = parts[0]; IPAddress ipAddress; if (IPAddress.TryParse(address, out ipAddress)) { arpScanResults.Add(ipAddress); } // end if } // end while arpScanProcess.WaitForExit(); } // end using return(arpScanResults); } // end method
public void DebinarizeConfigFile(string sourceFilePath, string destinationFilePath) { if (string.IsNullOrWhiteSpace(sourceFilePath) || !_file.Exists(sourceFilePath)) { throw new ArgumentException("Invalid binarized config file source path"); } if (string.IsNullOrWhiteSpace(destinationFilePath)) { throw new ArgumentException("Invalid debinarized config file destination path"); } System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo { WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal, FileName = $"{_cfgConverterFilePath}", Arguments = $@" -txt -dst ""{destinationFilePath}"" ""{sourceFilePath}""" }; _process.StartInfo = startInfo; _process.Start(); var successfullyExecuted = _process.WaitForExit(_configurationService.ConfigFileDebinarizationTimeout); if (!successfullyExecuted) { throw new TimeoutException("Attempted config file debinarization took too long to complete. Timeout: "); } }
internal int Execute(string prefix) { Defaults.Logger.Write(prefix, Path + _argumentBuilder.Build()); int exitCode = 0; using (IProcessWrapper process = CreateProcess()) { try { process.Start(); process.BeginOutputAndErrorReadLine(); if (!process.WaitForExit(_timeoutInMiliSeconds)) { HandleTimeout(process); } // if( _noErrorMessageWhenExitCodeZero && process.ExitCode == 0) // { // _output.Append( _error ); // _error.Clear(); // } _messageProcessor.Display(prefix, _output.ToString(), _error.ToString(), process.ExitCode); exitCode = process.ExitCode; //if we are supposed to fail on errors //and there was an error //and the calling code has decided not to deal with the error code (by setting SucceedOnNonZeroErrorCodes //then set the environment exit code if (OnError == OnError.Fail && exitCode != 0 && _succeedOnNonZeroErrorCodes == false) { BuildFile.SetErrorState(); throw new ApplicationException("Executable returned an error code of " + exitCode); } } catch (Exception e) { if (OnError == OnError.Fail) { throw; } Debug.Write(prefix, "An error occurred running a process but FailOnError was set to false. Error: " + e); } } this.ExitCode = exitCode; return(exitCode); }