/// <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 string Start <T>(string username) where T : IProcessWrapper { var x = typeof(T); Process = Activator.CreateInstance <T>(); Process.StartInfo = new ProcessStartInfo() { WorkingDirectory = Properties.Settings.Default.SeleniumPath, Arguments = CurrentArgs, FileName = CurrentFileName, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true }; Process.EnableRaisingEvents = true; if (username != null) { var cm = CredentialStore.GetCredential(username); Process.StartInfo.Domain = cm.Username.Split('\\')[0]; Process.StartInfo.UserName = cm.Username.Split('\\')[1]; var pass = cm.Password; Console.WriteLine(pass); Process.StartInfo.Password = cm.SecurePassword; } Process.Start(); Process.BeginOutputReadLine(); Process.BeginErrorReadLine(); var proc = new Process(); return(Process.GetProcessUser()); }
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: "); } }
public void Init() { _process = A.Fake<IProcessWrapper>(); _processManager = A.Fake<IProcessManager>(); A.CallTo(() => _processManager.GetProcess(Executable, Parameters)).Returns(_process); A.CallTo(() => _process.Start()).Invokes(x => InitStartInternalUpdates()).Returns(true); _command = new Command(_processManager, Name, Executable, Parameters, KillChildren); }
public void SendMessage(string message) { var info = new ProcessStartInfo { WorkingDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "sysnative"), FileName = "msg.exe", Arguments = string.Format(@" * ""{0}""", message), WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = true, Verb = "runas" }; _process.Start(info); }
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); }
public override Task <SessionHostInfo> CreateAndStart(int instanceNumber, GameResourceDetails gameResourceDetails, ISessionHostManager sessionHostManager) { SessionHostsStartInfo sessionHostStartInfo = gameResourceDetails.SessionHostsStartInfo; string sessionHostUniqueId = Guid.NewGuid().ToString("D"); string logFolderPathOnVm = Path.Combine(_vmConfiguration.VmDirectories.GameLogsRootFolderVm, sessionHostUniqueId); _systemOperations.CreateDirectory(logFolderPathOnVm); // Create the dumps folder as a subfolder of the logs folder string dumpFolderPathOnVm = Path.Combine(logFolderPathOnVm, VmDirectories.GameDumpsFolderName); _systemOperations.CreateDirectory(dumpFolderPathOnVm); ISessionHostConfiguration sessionHostConfiguration = new SessionHostProcessConfiguration(_vmConfiguration, _logger, _systemOperations, sessionHostStartInfo); string configFolderPathOnVm = _vmConfiguration.GetConfigRootFolderForSessionHost(instanceNumber); _systemOperations.CreateDirectory(configFolderPathOnVm); ProcessStartInfo processStartInfo = new ProcessStartInfo(); (string executableFileName, string arguments) = GetExecutableAndArguments(sessionHostStartInfo, instanceNumber); processStartInfo.FileName = executableFileName; processStartInfo.Arguments = arguments; processStartInfo.WorkingDirectory = sessionHostStartInfo.GameWorkingDirectory ?? Path.GetDirectoryName(executableFileName); processStartInfo.Environment.AddRange(sessionHostConfiguration.GetEnvironmentVariablesForSessionHost(instanceNumber, sessionHostUniqueId, sessionHostManager.VmAgentSettings)); _logger.LogInformation($"Starting process for session host with instance number {instanceNumber} and process info: FileName - {executableFileName}, Args - {arguments}."); SessionHostInfo sessionHost = sessionHostManager.AddNewSessionHost(sessionHostUniqueId, sessionHostStartInfo.AssignmentId, instanceNumber, sessionHostUniqueId, SessionHostType.Process); sessionHostConfiguration.Create(instanceNumber, sessionHostUniqueId, GetVmAgentIpAddress(), _vmConfiguration, sessionHostUniqueId); try { string processId = _processWrapper.Start(processStartInfo).ToString(); sessionHostManager.UpdateSessionHostTypeSpecificId(sessionHostUniqueId, processId); _logger.LogInformation($"Started process for session host. Instance Number: {instanceNumber}, UniqueId: {sessionHostUniqueId}, ProcessId: {processId}"); } catch (Exception exception) { _logger.LogException($"Failed to start process based host with instance number {instanceNumber}", exception); sessionHostManager.RemoveSessionHost(sessionHostUniqueId); sessionHost = null; } return(Task.FromResult(sessionHost)); }
public InstalledUpdate LaunchInstalledUpdate(InstalledUpdate installedUpdate) { if (installedUpdate == null) { throw new ArgumentNullException("installedUpdate"); } var fullCmdLine = _commandLineWrapper.Full; var arguments = _commandLineWrapper.Arguments; var filename = arguments[0]; var cmdArguments = fullCmdLine.Substring(fullCmdLine.IndexOf(filename) + filename.Length); if (cmdArguments.StartsWith("\"")) { cmdArguments = cmdArguments.Substring(1); } _processWrapper.Start(filename, cmdArguments.Trim()); return(installedUpdate); }
public void Start() { if (Disposed) { throw new ObjectDisposedException(GetType().Name); } if (_process != null) { Clean(); } _process = _manager.GetProcess(_executable, _parameters); _process.Exited += ProcessExited; try { _process.Start(); Log.Debug("Started !"); } catch (Exception e) { if (_process != null) { _process.Dispose(); _process = null; } Log.Error(string.Format("Unable to start command {0}: {1}", this, e.Message), e); } }
public void OnShowCopiedFiles() { _processWrapper.Start(_model.Settings.PathTo); }