Пример #1
0
 public ProcessCommandTests()
 {
     Container   = Substitute.For <IContainer>();
     ProcessIO   = Substitute.For <IProcessIO>();
     CommandArgs = Substitute.For <IRemoteCommandArgs>();
     Process     = Substitute.For <IContainerProcess>();
 }
Пример #2
0
        protected TaskCommandResult RunProcess(string workingDirectory, string executable, string[] processArguments)
        {
            string exePath = this.Container.ConvertToUserPathWithin(executable);

            string workingDir = String.IsNullOrWhiteSpace(workingDirectory)
                ? this.Container.Directory.UserPath
                : this.Container.ConvertToUserPathWithin(workingDirectory);

            var environment = this.CommandArgs.Environment.ToDictionary(kv => kv.Key,
                                                                        kv => this.Container.ConvertToUserPathWithin(kv.Value));

            var privileged = this.CommandArgs.Privileged;

            var processArgs = processArguments ?? new string[0];

            log.Trace("Running process{0} (WorkingDir {1}): {2} Args: {3}",
                      privileged ? " (privileged)" : " (non-privileged)",
                      workingDir,
                      exePath,
                      string.Join(" ", processArgs)
                      );

            var spec = new ProcessSpec
            {
                ExecutablePath     = exePath,
                Arguments          = processArguments,
                WorkingDirectory   = workingDir,
                Environment        = environment,
                DisablePathMapping = true,
                Privileged         = privileged,
            };

            IContainerProcess process = null;

            process = this.Container.Run(spec, this.IO);

            log.Trace("Process ID: '{0}'", process.Id);

            // These aren't in a using block intentionally - we don't want to
            // delete the files because they might be useful for debugging
            // if the app crashes.
            CreatePidLog(process.Id);
            CreateProcessEnvLog(process.Environment);

            int exitCode = process.WaitForExit();

            log.Trace("Process ended with exit code: {0}", exitCode);

            return(new TaskCommandResult(exitCode, null, null));
        }
Пример #3
0
 private static void WaitForExit(IWebSocketEventSender websocket, IContainerProcess process)
 {
     try
     {
         var exitCode = process.WaitForExit();
         websocket.SendEvent("close", exitCode.ToString());
         websocket.Flush();
         websocket.Close(System.Net.WebSockets.WebSocketCloseStatus.NormalClosure, "process finished");
     }
     catch (Exception e)
     {
         websocket.SendEvent("close", "-1");
         websocket.Flush();
         websocket.Close(System.Net.WebSockets.WebSocketCloseStatus.InternalServerError, e.Message);
     }
 }
Пример #4
0
 private static void WaitForExit(IWebSocketEventSender websocket, IContainerProcess process)
 {
     try
     {
         var exitCode = process.WaitForExit();
         websocket.SendEvent("close", exitCode.ToString());
         websocket.Flush();
         // websocket.Close(System.Net.WebSockets.WebSocketCloseStatus.NormalClosure, "process finished");
     }
     catch (Exception e)
     {
         websocket.SendEvent("close", "-1");
         websocket.Flush();
         // websocket.Close(System.Net.WebSockets.WebSocketCloseStatus.InternalServerError, e.Message);
     }
 }