Ejemplo n.º 1
0
        private CoffeeScriptExecutionInfo Execute(string prg, string commandLine)
        {
            string outPutFileName = String.Format(@"{0}\CoffeeScriptRunTimeOutput.txt", System.Environment.GetEnvironmentVariable("TEMP"));
            string batchFileName  = String.Format(@"{0}\CoffeeScriptRunTime.bat", System.Environment.GetEnvironmentVariable("TEMP"));
            var    e = new CoffeeScriptExecutionInfo();

            e.Time       = Environment.TickCount;
            e.ErrorLevel = -1;
            try {
                if (System.IO.File.Exists(outPutFileName))
                {
                    System.IO.File.Delete(outPutFileName);
                }

                e.CommandLine = String.Format(@"""{0}"" {1} >""{2}""", prg, commandLine, outPutFileName);
                System.IO.File.WriteAllText(batchFileName, e.CommandLine);

                ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe", String.Format(@"/c ""{0}"" ", batchFileName));
                processStartInfo.ErrorDialog     = false;
                processStartInfo.UseShellExecute = true;
                processStartInfo.WindowStyle     = ProcessWindowStyle.Hidden;
                Process process = new Process();
                process.StartInfo = processStartInfo;
                bool processStarted = process.Start();

                if (processStarted)
                {
                    process.WaitForExit();
                    e.ErrorLevel = process.ExitCode;
                    e.Output     = System.IO.File.ReadAllText(outPutFileName);
                }
            }
            catch (Exception ex) {
                e.ErrorOutput += String.Format("Error lanching the {0} = {1}", prg, ex.Message);
            }
            finally {
            }
            e.Time = Environment.TickCount - e.Time;
            return(e);
        }
        private CoffeeScriptExecutionInfo Execute(string prg, string commandLine) {

            string outPutFileName     = String.Format(@"{0}\CoffeeScriptRunTimeOutput.txt", System.Environment.GetEnvironmentVariable("TEMP"));
            string batchFileName      = String.Format(@"{0}\CoffeeScriptRunTime.bat", System.Environment.GetEnvironmentVariable("TEMP"));
            var e                     = new CoffeeScriptExecutionInfo();
            e.Time                    = Environment.TickCount;
            e.ErrorLevel              = -1;            
            try {                

                if(System.IO.File.Exists(outPutFileName))
                    System.IO.File.Delete(outPutFileName);

                e.CommandLine                           = String.Format(@"""{0}"" {1} >""{2}""",prg, commandLine, outPutFileName);
                System.IO.File.WriteAllText(batchFileName, e.CommandLine);

                ProcessStartInfo processStartInfo       = new ProcessStartInfo("cmd.exe", String.Format(@"/c ""{0}"" ", batchFileName));
                processStartInfo.ErrorDialog            = false;
                processStartInfo.UseShellExecute        = true;
                processStartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
                Process process                         = new Process();
                process.StartInfo                       = processStartInfo;
                bool processStarted                     = process.Start();

                if (processStarted) {
                    process.WaitForExit();                    
                    e.ErrorLevel = process.ExitCode;
                    e.Output = System.IO.File.ReadAllText(outPutFileName);
                }
            }
            catch (Exception ex) {

                e.ErrorOutput += String.Format("Error lanching the {0} = {1}", prg, ex.Message);
            }
            finally {
                
            }
            e.Time = Environment.TickCount - e.Time;
            return e;
        }