コード例 #1
0
		// TODO: Get rid of "suppressImportWarnings" once MTASC releases a new version
		// with that option fixed.

		public static bool Run(string fileName, string arguments, bool ignoreExitCode)
		{
			if (!File.Exists(fileName))
				throw new FileNotFoundException("The program '"+fileName+"' was not found.",fileName);

			Process process = new Process();
			process.StartInfo.UseShellExecute = false;
			process.StartInfo.RedirectStandardOutput = true;
			process.StartInfo.RedirectStandardError = true;
			process.StartInfo.CreateNoWindow = true;
			process.StartInfo.FileName = fileName;
			process.StartInfo.Arguments = arguments;
			process.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
			process.Start();

			// capture output in a separate thread
			LineFilter stdoutFilter = new LineFilter(process.StandardOutput,Console.Out);
			LineFilter stderrFilter = new LineFilter(process.StandardError,Console.Error);

			Thread outThread = new Thread(new ThreadStart(stdoutFilter.Filter));
			Thread errThread = new Thread(new ThreadStart(stderrFilter.Filter));

			outThread.Start();
			errThread.Start();

			process.WaitForExit();

			outThread.Join(1000);
			errThread.Join(1000);
			
			return (ignoreExitCode) ? stderrFilter.Lines == 0 : process.ExitCode == 0;
		}
コード例 #2
0
        // TODO: Get rid of "suppressImportWarnings" once MTASC releases a new version
        // with that option fixed.

        public static bool Run(string fileName, string arguments, bool ignoreExitCode)
        {
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("The program '" + fileName + "' was not found.", fileName);
            }

            Process process = new Process();

            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.FileName         = fileName;
            process.StartInfo.Arguments        = arguments;
            process.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
            process.Start();

            // capture output in a separate thread
            LineFilter stdoutFilter = new LineFilter(process.StandardOutput, Console.Out);
            LineFilter stderrFilter = new LineFilter(process.StandardError, Console.Error);

            Thread outThread = new Thread(new ThreadStart(stdoutFilter.Filter));
            Thread errThread = new Thread(new ThreadStart(stderrFilter.Filter));

            outThread.Start();
            errThread.Start();

            process.WaitForExit();

            outThread.Join(1000);
            errThread.Join(1000);

            return((ignoreExitCode) ? stderrFilter.Lines == 0 : process.ExitCode == 0);
        }