public void Start() { process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); if (debug) { var maxWaitUntil = DateTime.Now.AddSeconds(30); System.Threading.Thread.Sleep(100); while (shouldAttachToMain == null && maxWaitUntil > DateTime.Now) { System.Threading.Thread.Sleep(100); } if (shouldAttachToMain != null && shouldAttachToMain.Value) { AttachToProcess(process.Id); } } }
private void RunProcess(string exePath, string arguments) { WriteToOutputWindow("Starting build..."); WriteToOutputWindow(exePath + " " + arguments); WriteToOutputWindow(string.Empty); using (System.Diagnostics.Process proc = new System.Diagnostics.Process()) { proc.StartInfo.FileName = exePath; proc.StartInfo.Arguments = arguments; proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.RedirectStandardOutput = true; proc.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(proc_OutputDataReceived); proc.Start(); proc.BeginOutputReadLine(); proc.WaitForExit(); } }
private void UseNHQG(Assembly assembly) { System.Diagnostics.Process nhqg = new System.Diagnostics.Process(); ProcessStartInfo startInfo = new ProcessStartInfo(); DirectoryInfo info = new DirectoryInfo(System.Environment.GetEnvironmentVariable("TEMP")); string tempFileFolderName = Guid.NewGuid().ToString("N"); DirectoryInfo tempFileFolder = null; try { tempFileFolder = info.CreateSubdirectory(tempFileFolderName); startInfo.FileName = _model.NHQGExecutable; startInfo.WorkingDirectory = Path.GetDirectoryName(_model.NHQGExecutable); string[] args = new string[4]; args[0] = "/lang:" + (_language == CodeLanguage.CSharp ? "CS": "VB"); args[1] = "/files:\"" + assembly.Location + "\""; args[2] = "/out:\"" + tempFileFolder.FullName + "\""; args[3] = "/ns:" + _namespace; startInfo.Arguments = string.Join(" ", args); startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.ErrorDialog = false; startInfo.CreateNoWindow = true; startInfo.RedirectStandardOutput = true; startInfo.UseShellExecute = false; nhqg.StartInfo = startInfo; Log("Running NHQG with parameters: " + String.Join(" ", args)); nhqg.Start(); StreamReader output = nhqg.StandardOutput; nhqg.WaitForExit(); // Timeout? if (nhqg.ExitCode != 0) { throw new TargetException("NHQG exited with code " + nhqg.ExitCode.ToString()); } else { string consoleOut = output.ReadToEnd(); if (!string.IsNullOrEmpty(consoleOut) && consoleOut.StartsWith("An error occured:")) { throw new TargetException("NHQG exited with the following error:\n\n" + consoleOut); } else { foreach (FileInfo file in tempFileFolder.GetFiles()) { string filePath = Path.Combine(_modelFilePath, file.Name); file.CopyTo(filePath , true); AddToProject(filePath, prjBuildAction.prjBuildActionCompile); } } } } finally { if (tempFileFolder != null) tempFileFolder.Delete(true); } }