本文整理汇总了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);
}
示例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();
}
示例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;
}