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.StandardOutputEncoding = Encoding.Default;
            process.StartInfo.StandardErrorEncoding  = Encoding.Default;
            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);
        }
Esempio n. 2
0
		public static bool Run(string fileName, string arguments, bool ignoreExitCode, bool mergeErrors)
		{
			//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.StandardOutputEncoding = Encoding.Default;
            process.StartInfo.StandardErrorEncoding = Encoding.Default;
            process.StartInfo.CreateNoWindow = true;
			process.StartInfo.FileName = Environment.ExpandEnvironmentVariables(fileName);
			process.StartInfo.Arguments = Environment.ExpandEnvironmentVariables(arguments);
			process.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
			process.Start();

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

			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;
		}
        public static bool Run(string fileName, string arguments, bool ignoreExitCode, bool mergeErrors)
        {
            // CrossOver native call
            Boolean isNative = fileName == "FDEXE.sh" || Path.GetExtension(fileName) == ".command";

            Process process = new Process();

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

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

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

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

            // Call is redirected, process is lost, will finish when done.
            if (isNative)
            {
                return(stderrFilter.Lines == 0);
            }

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

            return((ignoreExitCode) ? stderrFilter.Lines == 0 : process.ExitCode == 0);
        }
        public static bool Run(string fileName, string arguments, bool ignoreExitCode, bool mergeErrors)
        {
            // CrossOver native call
            Boolean isNative = fileName == "FDEXE.sh" || Path.GetExtension(fileName) == ".command";

            Process process = new Process();
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.StandardOutputEncoding = Encoding.Default;
            process.StartInfo.StandardErrorEncoding = Encoding.Default;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.FileName = Environment.ExpandEnvironmentVariables(fileName);
            process.StartInfo.Arguments = Environment.ExpandEnvironmentVariables(arguments);
            process.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
            process.Start();
            
            // capture output in a separate thread
            LineFilter stdoutFilter = new LineFilter(process.StandardOutput, Console.Out, false);
            LineFilter stderrFilter = new LineFilter(process.StandardError, Console.Error, mergeErrors);

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

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

            // Call is redirected, process is lost, will finish when done.
            if (isNative) return stderrFilter.Lines == 0;

            process.WaitForExit();
            outThread.Join(1000);
            errThread.Join(1000);
            
            return (ignoreExitCode) ? stderrFilter.Lines == 0 : process.ExitCode == 0;
        }