Example #1
0
        public virtual string Execute([NotNull] params string[] arguments)
        {
            #region Sanity checks
            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }
            #endregion

            Process process;
            try
            {
                process = GetStartInfo(arguments).Start();
                Debug.Assert(process != null);
            }
            #region Error handling
            catch (IOException ex)
            {
                throw new IOException(string.Format(Resources.UnableToLaunchBundled, AppBinary), ex);
            }
            #endregion

            var stdout = new StreamConsumer(process.StandardOutput);
            var stderr = new StreamConsumer(process.StandardError);
            var stdin  = process.StandardInput;

            InitStdin(stdin);
            do
            {
                HandlePending(stderr, stdin);
            } while (!process.WaitForExit(50));
            stdout.WaitForEnd();
            stderr.WaitForEnd();
            HandlePending(stderr, stdin);

            return(stdout.ToString());
        }