本文整理汇总了C#中System.Diagnostics.ProcessStartInfo.ExecuteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# ProcessStartInfo.ExecuteAsync方法的具体用法?C# ProcessStartInfo.ExecuteAsync怎么用?C# ProcessStartInfo.ExecuteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.ProcessStartInfo
的用法示例。
在下文中一共展示了ProcessStartInfo.ExecuteAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileAsync
public async Task<CompilerResult> CompileAsync(string sourceFileName, string targetFileName)
{
if (RequireMatchingFileName &&
Path.GetFileName(targetFileName) != Path.GetFileNameWithoutExtension(sourceFileName) + TargetExtension &&
Path.GetFileName(targetFileName) != Path.GetFileNameWithoutExtension(sourceFileName) + ".min" + TargetExtension)
throw new ArgumentException(ServiceName + " cannot compile to a targetFileName with a different name. Only the containing directory can be different.", "targetFileName");
var mapFileName = GetMapFileName(sourceFileName, targetFileName);
var scriptArgs = GetArguments(sourceFileName, targetFileName, mapFileName);
var errorOutputFile = Path.GetTempFileName();
var cmdArgs = string.Format("\"{0}\" \"{1}\"", NodePath, CompilerPath);
cmdArgs = string.Format("/c \"{0} {1} > \"{2}\" 2>&1\"", cmdArgs, scriptArgs, errorOutputFile);
ProcessStartInfo start = new ProcessStartInfo("cmd")
{
WindowStyle = ProcessWindowStyle.Hidden,
WorkingDirectory = Path.GetDirectoryName(sourceFileName),
Arguments = cmdArgs,
UseShellExecute = false,
CreateNoWindow = true
};
try
{
ProjectHelpers.CheckOutFileFromSourceControl(targetFileName);
mapFileName = mapFileName ?? targetFileName + ".map";
if (GenerateSourceMap)
ProjectHelpers.CheckOutFileFromSourceControl(mapFileName);
using (var process = await start.ExecuteAsync())
{
if (targetFileName != null)
await MoveOutputContentToCorrectTarget(targetFileName);
return await ProcessResult(
process,
(await FileHelpers.ReadAllTextRetry(errorOutputFile)).Trim(),
sourceFileName,
targetFileName,
mapFileName
);
}
}
finally
{
File.Delete(errorOutputFile);
if (!GenerateSourceMap)
File.Delete(mapFileName);
}
}
示例2: Compile
public async Task<CompilerResult> Compile(string sourceFileName, string targetFileName)
{
if (!CheckPrerequisites(sourceFileName))
return null;
var scriptArgs = GetArguments(sourceFileName, targetFileName);
var errorOutputFile = Path.GetTempFileName();
var cmdArgs = string.Format("\"{0}\" \"{1}\"", NodePath, CompilerPath);
cmdArgs = string.Format("/c \"{0} {1} > \"{2}\" 2>&1\"", cmdArgs, scriptArgs, errorOutputFile);
ProcessStartInfo start = new ProcessStartInfo("cmd")
{
WindowStyle = ProcessWindowStyle.Hidden,
WorkingDirectory = Path.GetDirectoryName(sourceFileName),
Arguments = cmdArgs,
UseShellExecute = false,
CreateNoWindow = true
};
try
{
if (!ProjectHelpers.CheckOutFileFromSourceControl(sourceFileName))
{
// Someone else have this file checked out
Logger.Log("Could not check the file out of source control");
return null;
}
ProjectHelpers.CheckOutFileFromSourceControl(targetFileName);
using (var process = await start.ExecuteAsync())
{
return ProcessResult(
process,
File.ReadAllText(errorOutputFile).Trim(),
sourceFileName,
targetFileName
);
}
}
finally
{
File.Delete(errorOutputFile);
}
}
示例3: Compile
public async Task<CompilerResult> Compile(string sourceFileName, string targetFileName)
{
var scriptArgs = GetArguments(sourceFileName, targetFileName);
var errorOutputFile = Path.GetTempFileName();
var cmdArgs = string.Format("\"{0}\" \"{1}\"", NodePath, CompilerPath);
cmdArgs = string.Format("/c \"{0} {1} > \"{2}\" 2>&1\"", cmdArgs, scriptArgs, errorOutputFile);
ProcessStartInfo start = new ProcessStartInfo("cmd")
{
WindowStyle = ProcessWindowStyle.Hidden,
WorkingDirectory = Path.GetDirectoryName(sourceFileName),
Arguments = cmdArgs,
UseShellExecute = false,
CreateNoWindow = true
};
try
{
using (var process = await start.ExecuteAsync())
{
string errorText = "";
// Subjected to change, depending on https://github.com/andrew/node-sass/issues/207
if (File.Exists(errorOutputFile))
errorText = File.ReadAllText(errorOutputFile).Trim();
return ProcessResult(process, errorText, sourceFileName, targetFileName);
}
}
finally
{
File.Delete(errorOutputFile);
}
}
示例4: CompressFile
private async Task<CompressionResult> CompressFile(string fileName)
{
string targetFile = Path.ChangeExtension(Path.GetTempFileName(), Path.GetExtension(fileName));
ProcessStartInfo start = new ProcessStartInfo("cmd")
{
WindowStyle = ProcessWindowStyle.Hidden,
WorkingDirectory = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), @"Resources\tools\"),
Arguments = GetArguments(fileName, targetFile),
UseShellExecute = false,
CreateNoWindow = true,
};
try
{
using (var process = await start.ExecuteAsync())
{
return new CompressionResult(fileName, targetFile);
}
}
catch
{
CompressionResult result = new CompressionResult(fileName, targetFile);
File.Delete(targetFile);
return result;
}
}
示例5: CompileAsync
public async Task<CompilerResult> CompileAsync(string sourceFileName, string targetFileName)
{
if (WEIgnore.TestWEIgnore(sourceFileName, this is ILintCompiler ? "linter" : "compiler", ServiceName.ToLowerInvariant()))
{
Logger.Log(String.Format(CultureInfo.CurrentCulture, "{0}: The file {1} is ignored by .weignore. Skipping..", ServiceName, Path.GetFileName(sourceFileName)));
return await CompilerResultFactory.GenerateResult(sourceFileName, targetFileName, string.Empty, false, string.Empty, Enumerable.Empty<CompilerError>(), true);
}
if (RequireMatchingFileName &&
Path.GetFileName(targetFileName) != Path.GetFileNameWithoutExtension(sourceFileName) + TargetExtension &&
Path.GetFileName(targetFileName) != Path.GetFileNameWithoutExtension(sourceFileName) + ".min" + TargetExtension)
throw new ArgumentException(ServiceName + " cannot compile to a targetFileName with a different name. Only the containing directory can be different.", "targetFileName");
string mapFileName = GetMapFileName(sourceFileName, targetFileName),
tempTarget = Path.GetTempFileName(),
scriptArgs = await GetArguments(sourceFileName, tempTarget, mapFileName),
errorOutputFile = Path.GetTempFileName(),
cmdArgs = string.Format("\"{0}\" \"{1}\"", NodePath, CompilerPath);
cmdArgs = string.Format("/c \"{0} {1} > \"{2}\" 2>&1\"", cmdArgs, scriptArgs, errorOutputFile);
ProcessStartInfo start = new ProcessStartInfo("cmd")
{
WindowStyle = ProcessWindowStyle.Hidden,
WorkingDirectory = Path.GetDirectoryName(sourceFileName),
Arguments = cmdArgs,
UseShellExecute = false,
CreateNoWindow = true
};
try
{
mapFileName = mapFileName ?? targetFileName + ".map";
using (var process = await start.ExecuteAsync())
{
if (targetFileName != null)
await MoveOutputContentToCorrectTarget(targetFileName);
// Another ugly hack for https://github.com/jashkenas/coffeescript/issues/3526
if (ServiceName.ToLowerInvariant().IndexOf("coffeescript") >= 0 || ServiceName.ToLowerInvariant().IndexOf("livescript") >= 0)
{
tempTarget = Path.Combine(Path.GetDirectoryName(tempTarget), Path.GetFileName(targetFileName));
mapFileName = Path.ChangeExtension(tempTarget, ".map");
}
return await ProcessResult(
process,
(await FileHelpers.ReadAllTextRetry(errorOutputFile)).Trim(),
sourceFileName,
tempTarget,
targetFileName,
mapFileName
);
}
}
finally
{
File.Delete(errorOutputFile);
File.Delete(tempTarget);
if (ManagedSourceMap && !GenerateSourceMap)
File.Delete(mapFileName);
}
}