public SbError Run(SbPlatformShellCommand command) { var grpcSbPlatformShellCommand = new GrpcSbPlatformShellCommand { Command = command.GetCommand() }; var request = new RunRequest { ShellCommand = grpcSbPlatformShellCommand }; RunResponse response = null; if (connection.InvokeRpc(() => { response = client.Run(request); })) { command.SetOutput(response.Output); command.SetSignal(response.Signal); command.SetStatus(response.Status); return(sbErrorFactory.Create(response.Error)); } var grpcSbError = new GrpcSbError { Success = false, Error = "Rpc error while calling Run. Inspect the logs for more information." }; return(sbErrorFactory.Create(grpcSbError)); }
public SbError Run(SbPlatformShellCommand command) { if (_runStatuses.Count > 0) { return(new SbErrorStub(_runStatuses.Dequeue())); } var commandText = command.GetCommand(); if (commandText.StartsWith("pidof")) { var processName = commandText.Substring("pidof".Length + 1) .TrimStart('"') .TrimEnd('"'); var process = _processes.FirstOrDefault(p => p.Name == processName); if (process == null) { return(new SbErrorStub(false, $"unknown process: {processName}")); } command.SetOutput(process.Pid.ToString()); return(new SbErrorStub(true)); } if (_processCommandToOutput.TryGetValue(commandText, out string output)) { if (output == null) { command.SetStatus(1); command.SetOutput(""); } else { command.SetStatus(0); command.SetOutput(output); } return(new SbErrorStub(true)); } throw new NotSupportedException( $"The command is not supported: Command: {commandText}"); }