当前位置: 首页>>代码示例>>C#>>正文


C# ProcessStartInfo.Run方法代码示例

本文整理汇总了C#中System.Diagnostics.ProcessStartInfo.Run方法的典型用法代码示例。如果您正苦于以下问题:C# ProcessStartInfo.Run方法的具体用法?C# ProcessStartInfo.Run怎么用?C# ProcessStartInfo.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Diagnostics.ProcessStartInfo的用法示例。


在下文中一共展示了ProcessStartInfo.Run方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public static string Execute(string[] args, string[] scriptArgs, string logFile, string workingDirectory)
        {
            var commandArgs = new List<string>(args);
            if (scriptArgs.Length > 0)
            {
                commandArgs.Add("--");
                commandArgs.AddRange(scriptArgs);
            }

#if DEBUG
            var config = "Debug";
#else
            var config = "Release";
#endif

            var exe = Path.GetFullPath(
                Path.Combine("..", "..", "..", "..", "src", "ScriptCs", "bin", config, "scriptcs.exe"));

            var info = new ProcessStartInfo
            {
                FileName = isMono
                    ? "mono"
                    : exe,
                Arguments = isMono
                    ? string.Concat(exe, " ", string.Join(" ", commandArgs))
                    : string.Join(" ", commandArgs),
                WorkingDirectory = workingDirectory,
                UseShellExecute = false,
                CreateNoWindow = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true
            };

            return info.Run(logFile);
        }
开发者ID:selony,项目名称:scriptcs,代码行数:35,代码来源:ScriptCsExe.cs

示例2: OnActionsExecuted

        protected override void OnActionsExecuted()
        {
            if (this.Command == null)
            {
                throw new InvalidOperationException("The command is null.");
            }

            if (string.IsNullOrWhiteSpace(this.Command))
            {
                throw new InvalidOperationException("The command is invalid.");
            }

            var info = new ProcessStartInfo
            {
                FileName = this.Command,
                Arguments = this.Args == null
                    ? null
                    : string.Join(" ", this.Args.Where(arg => !string.IsNullOrWhiteSpace(arg))),

                WorkingDirectory = this.WorkingDirectory,
                UseShellExecute = false,
            };

            var argString = string.IsNullOrEmpty(info.Arguments)
                ? string.Empty
                : " " + string.Join(" ", info.Arguments);

            var workingDirectoryString = string.IsNullOrEmpty(info.WorkingDirectory)
                ? string.Empty
                : string.Format(CultureInfo.InvariantCulture, " with working directory '{0}'", info.WorkingDirectory);

            Console.WriteLine("Executing '{0}{1}'{2}...", info.FileName, argString, workingDirectoryString);
            info.Run();
        }
开发者ID:pgermishuys,项目名称:bau,代码行数:34,代码来源:Exec.cs

示例3: Execute

        private static string Execute(
            IEnumerable<string> args, IEnumerable<string> scriptArgs, ScenarioDirectory directory)
        {
            var commandArgs = new List<string>(args);
            var scriptArgsArray = scriptArgs.ToArray();
            if (scriptArgsArray.Any())
            {
                commandArgs.Add("--");
                commandArgs.AddRange(scriptArgsArray);
            }

            #if DEBUG
            var config = "Debug";
            #else
            var config = "Release";
            #endif

            var exe = Path.GetFullPath(
                Path.Combine("..", "..", "..", "..", "src", "ScriptCs", "bin", config, "scriptcs.exe"));

            var info = new ProcessStartInfo
            {
                FileName = isMono
                    ? "mono"
                    : exe,
                Arguments = isMono
                    ? string.Concat(exe, " ", string.Join(" ", commandArgs))
                    : string.Join(" ", commandArgs),
                WorkingDirectory = directory.Name,
                UseShellExecute = false,
                CreateNoWindow = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true
            };
            var result = info.Run(Path.GetFileName(directory.Name) + ".log");
            if (result.Item1 != 0)
            {
                var message = string.Format(
                    CultureInfo.InvariantCulture,
                    "scriptcs.exe exited with code {0}. The output was: {1}",
                    result.Item1.ToString(CultureInfo.InvariantCulture),
                    result.Item2);

                throw new ScriptCsException(message);
            }

            return result.Item2;
        }
开发者ID:AsCloud,项目名称:scriptcs,代码行数:48,代码来源:ScriptCsExe.cs


注:本文中的System.Diagnostics.ProcessStartInfo.Run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。