Exemplo n.º 1
0
        public RemoteExecutableResults Run(string arguments)
        {
            using (Process process = new Process())
            {
                process.StartInfo.FileName               = _executablePath;
                process.StartInfo.Arguments              = arguments;
                process.StartInfo.WorkingDirectory       = this.WorkingDirectory;
                process.StartInfo.CreateNoWindow         = true;
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.Start();

                ReadToEndDelegate readToEnd       = new ReadToEndDelegate(process.StandardOutput.ReadToEnd);
                IAsyncResult      readToEndResult = readToEnd.BeginInvoke(null, null);

                try
                {
                    process.WaitForExit(_millisecondsToWait);
                }
                catch (System.ComponentModel.Win32Exception win32Exception)
                {
                    throw new TimeoutException(
                              String.Format("Process {0} failed to finish in less than {1} seconds.{2}Exception information:{2}{3}",
                                            _executablePath,
                                            _millisecondsToWait / 1000,
                                            System.Environment.NewLine,
                                            win32Exception.Message));
                }
                catch (System.SystemException systemException)
                {
                    throw new TimeoutException(
                              String.Format("Process {0} failed to finish in less than {1} seconds.{2}Exception information:{2}{3}",
                                            _executablePath,
                                            _millisecondsToWait / 1000,
                                            System.Environment.NewLine,
                                            systemException.Message));
                }
                string output = readToEnd.EndInvoke(readToEndResult);
                RemoteExecutableResults result = new RemoteExecutableResults();
                result.ExitCode = process.ExitCode;
                result.Output   = output;
                return(result);
            }
        }
Exemplo n.º 2
0
        public RemoteExecutableResults Run(string arguments)
        {
            using (Process process = new Process())
            {
                process.StartInfo.FileName = _executablePath;
                process.StartInfo.Arguments = arguments;
                process.StartInfo.WorkingDirectory = this.WorkingDirectory;
                process.StartInfo.CreateNoWindow = true;
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.Start();

                ReadToEndDelegate readToEnd = new ReadToEndDelegate(process.StandardOutput.ReadToEnd);
                IAsyncResult readToEndResult = readToEnd.BeginInvoke(null, null);

                try
                {
                    process.WaitForExit(_millisecondsToWait);
                }
                catch (System.ComponentModel.Win32Exception win32Exception)
                {
                    throw new TimeoutException(
                        String.Format("Process {0} failed to finish in less than {1} seconds.{2}Exception information:{2}{3}",
                            _executablePath,
                            _millisecondsToWait / 1000,
                            System.Environment.NewLine,
                            win32Exception.Message));
                }
                catch (System.SystemException systemException)
                {
                    throw new TimeoutException(
                        String.Format("Process {0} failed to finish in less than {1} seconds.{2}Exception information:{2}{3}",
                            _executablePath,
                            _millisecondsToWait / 1000,
                            System.Environment.NewLine,
                            systemException.Message));
                }
                string output = readToEnd.EndInvoke(readToEndResult);
                RemoteExecutableResults result = new RemoteExecutableResults();
                result.ExitCode = process.ExitCode;
                result.Output = output;
                return result;
            }
        }
Exemplo n.º 3
0
        public RemoteExecutableResults ExecuteFile(string workingDirectory, string filePath, string arguments)
        {
            AuthenicateAssert();

            string expandedFilePath = Environment.ExpandEnvironmentVariables(filePath);
            string expandedWorkingDirectory = Environment.ExpandEnvironmentVariables(workingDirectory);
            Console.WriteLine("Attempting to execute file:" + expandedFilePath + " " + arguments);
            RemoteExecutableResults results = new RemoteExecutableResults();
            try
            {
                results =ExecutableFile.Execute(filePath, expandedWorkingDirectory, arguments);
            }
            catch (Exception exc)
            {
                results.ExitCode = 1;
                results.Output = exc.ToString();
            }
            return results;
        }
Exemplo n.º 4
0
        public RemoteExecutableResults ExecuteFile(string workingDirectory, string filePath, string arguments)
        {
            AuthenicateAssert();

            string expandedFilePath         = Environment.ExpandEnvironmentVariables(filePath);
            string expandedWorkingDirectory = Environment.ExpandEnvironmentVariables(workingDirectory);

            Console.WriteLine("Attempting to execute file:" + expandedFilePath + " " + arguments);
            RemoteExecutableResults results = new RemoteExecutableResults();

            try
            {
                results = ExecutableFile.Execute(filePath, expandedWorkingDirectory, arguments);
            }
            catch (Exception exc)
            {
                results.ExitCode = 1;
                results.Output   = exc.ToString();
            }
            return(results);
        }