Beispiel #1
0
        public Process CreateHiddenProcess(string appPath, string args, CmdOptions k)
        {
            var o = k ?? CmdOptions.Default;

            return(new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = appPath,
                    Arguments = args,
                    CreateNoWindow = o.CreateNoWindow,
                    WindowStyle = o.WindowStyle,
                    RedirectStandardOutput = o.RedirectStdOut,
                    UseShellExecute = o.UseOSShell,
                    WorkingDirectory = o.WorkingDirectory
                }
            });
        }
Beispiel #2
0
        public CommandLineRunResult Run(string appPath, string args, CmdOptions o, bool waitForExit)
        {
            var process = CreateHiddenProcess(appPath, args, o);

            var res = new CommandLineRunResult
            {
                AppPath = appPath,
                Args    = args
            };

            try
            {
                if (waitForExit)
                {
                    process.Start();
                    res.Output = process.StandardOutput.ReadToEnd();
                    process.WaitForExit();
                    res.ExitType = CommandLineExitTypes.Ok;
                    res.ExitCode = process.ExitCode;
                    if (process.HasExited == false)
                    {
                        process.Kill();
                    }
                }
                else
                {
                    process.Start();
                    res.Output = process.StandardOutput.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                res.ExitCode = int.MaxValue;
                res.ExitType = CommandLineExitTypes.ExceptionBeforeRun;
                res.Msg      = ex.ToString();
            }

            return(res);
        }
Beispiel #3
0
 static CmdOptions()
 {
     Default = new CmdOptions();
 }