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


C# ProcessStartInfo.ExecuteAsync方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:hanskishore,项目名称:WebEssentials2013,代码行数:57,代码来源:NodeExecutorBase.cs

示例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);
            }
        }
开发者ID:Nangal,项目名称:WebEssentials2013,代码行数:48,代码来源:NodeExecutorBase.cs

示例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);
            }
        }
开发者ID:NickCraver,项目名称:WebEssentials2013,代码行数:37,代码来源:NodeExecutorBase.cs

示例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;
            }
        }
开发者ID:Nangal,项目名称:WebEssentials2013,代码行数:27,代码来源:ImageCompressor.cs

示例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);
            }
        }
开发者ID:kradcliffe,项目名称:WebEssentials2013,代码行数:64,代码来源:NodeExecutorBase.cs


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