Bug track (avec utilisation de process)

Description

Pour développer un programme, il est bien utile d'utiliser la sortie console, histoire d'afficher deux ou trois informations. Sous SharpDevelop, il est possible de dire que l'on veut que la console reste affichée même après la fin du programme. Le problème, c'est que parfois, certaines erreurs plantent le programme et ferment aussi la console, qui contient parfois des informations très importantes pour pouvoir débugger. Mon programme permet donc de lancer un exécutable, et d'en afficher les sorties standard et d'erreur à la fin de son exécution. C'est pas du grand art, et c'est pas non plus très compliqué à faire, mais parfois, qu'est-ce que ca dépanne !

Source / Exemple :


/*

  • Created by SharpDevelop.
  • User: Yo
  • Date: 24/11/2004
  • Time: 17:56
  • To change this template use Tools | Options | Coding | Edit Standard Headers.
  • /
using System; using System.Drawing; using System.Windows.Forms; using System.Diagnostics; namespace BugTrack { /// <summary> /// Description of MainForm. /// </summary> public class MainForm : System.Windows.Forms.Form { private System.Windows.Forms.TabControl tabControl1; private System.Windows.Forms.Button button1; private System.Windows.Forms.TextBox Standard; private System.Windows.Forms.TabPage tabPage1; private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.OpenFileDialog opf; private System.Windows.Forms.Button button2; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox error; public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); // // TODO: Add constructor code after the InitializeComponent() call. // } [STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); } #region Windows Forms Designer generated code /// <summary> /// This method is required for Windows Forms designer support. /// Do not change the method contents inside the source code editor. The Forms designer might /// not be able to load this method if it was changed manually. /// </summary> private void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm)); this.error = new System.Windows.Forms.TextBox(); this.textBox1 = new System.Windows.Forms.TextBox(); this.button2 = new System.Windows.Forms.Button(); this.opf = new System.Windows.Forms.OpenFileDialog(); this.tabPage2 = new System.Windows.Forms.TabPage(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.Standard = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage2.SuspendLayout(); this.tabPage1.SuspendLayout(); this.tabControl1.SuspendLayout(); this.SuspendLayout(); // // error // this.error.Dock = System.Windows.Forms.DockStyle.Fill; this.error.Location = new System.Drawing.Point(0, 0); this.error.Multiline = true; this.error.Name = "error"; this.error.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.error.Size = new System.Drawing.Size(648, 302); this.error.TabIndex = 1; this.error.Text = ""; // // textBox1 // this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.textBox1.Location = new System.Drawing.Point(8, 8); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(544, 20); this.textBox1.TabIndex = 0; this.textBox1.Text = ""; // // button2 // this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button2.Image = ((System.Drawing.Image)(resources.GetObject("button2.Image"))); this.button2.Location = new System.Drawing.Point(560, 8); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(24, 24); this.button2.TabIndex = 3; this.button2.Click += new System.EventHandler(this.Button2Click); // // opf // this.opf.DefaultExt = "*.exe"; // // tabPage2 // this.tabPage2.Controls.Add(this.error); this.tabPage2.Location = new System.Drawing.Point(4, 22); this.tabPage2.Name = "tabPage2"; this.tabPage2.Size = new System.Drawing.Size(648, 302); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "Error"; // // tabPage1 // this.tabPage1.Controls.Add(this.Standard); this.tabPage1.Location = new System.Drawing.Point(4, 22); this.tabPage1.Name = "tabPage1"; this.tabPage1.Size = new System.Drawing.Size(648, 302); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "Standard"; // // Standard // this.Standard.Dock = System.Windows.Forms.DockStyle.Fill; this.Standard.Location = new System.Drawing.Point(0, 0); this.Standard.Multiline = true; this.Standard.Name = "Standard"; this.Standard.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.Standard.Size = new System.Drawing.Size(648, 302); this.Standard.TabIndex = 0; this.Standard.Text = ""; // // button1 // this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button1.Location = new System.Drawing.Point(592, 8); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(72, 24); this.button1.TabIndex = 1; this.button1.Text = "Go !"; this.button1.Click += new System.EventHandler(this.Button1Click); // // tabControl1 // this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tabControl1.Controls.Add(this.tabPage1); this.tabControl1.Controls.Add(this.tabPage2); this.tabControl1.Location = new System.Drawing.Point(8, 40); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; this.tabControl1.Size = new System.Drawing.Size(656, 328); this.tabControl1.TabIndex = 2; // // MainForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(672, 374); this.Controls.Add(this.button2); this.Controls.Add(this.tabControl1); this.Controls.Add(this.button1); this.Controls.Add(this.textBox1); this.Name = "MainForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "MainForm"; this.tabPage2.ResumeLayout(false); this.tabPage1.ResumeLayout(false); this.tabControl1.ResumeLayout(false); this.ResumeLayout(false); } #endregion void Button1Click(object sender, System.EventArgs e) { this.WindowState = FormWindowState.Minimized; Process p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.FileName = this.textBox1.Text; p.Start(); this.Standard.Text = p.StandardOutput.ReadToEnd(); this.error.Text = p.StandardError.ReadToEnd(); p.WaitForExit(); this.WindowState = FormWindowState.Normal; } void Button2Click(object sender, System.EventArgs e){ if(opf.ShowDialog(this) == DialogResult.OK){ this.textBox1.Text = opf.FileName; } } } }

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.