By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,750 Members | 1,456 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,750 IT Pros & Developers. It's quick & easy.

Gow to redirect output from gdb.exe in C#

P: 1
Hello,
I am developing a console application to invoke gdb session and log in the communication between my application and gdb.
I opened gdb as a new process and tried to redirect the input and output of the process to a streamwriter.But its not working.

I am able to redirect the standard input for the gdb process i.e. I can issue commands from my application to gdb but I am not able to redirect its standard output. The gdb process does not start itself. I also tried to pass "> myfile.txt" as a command line argument to the process while invoking for rediretion. But it also does not help.

Can somebody help me in this?

The sample code is here:



Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.IO;
  3. using System.Diagnostics;
  4.  
  5. namespace TeeBetweenGDBAndIDE
  6. {
  7.     /// <summary>
  8.     /// Summary description for Class1.
  9.    /// </summary>
  10.    class Class1
  11.   {
  12.     /// <summary>
  13.     /// The main entry point for the application.
  14.     /// </summary>
  15.     [STAThread]
  16.     static void Main(string[] args)
  17.     {
  18.         //
  19.         // TODO: Add code to start application here
  20.         //
  21.         try
  22.         {
  23.             Process p = new Process();
  24.             StreamWriter sw;
  25.  
  26.  
  27.             StreamWriter swLogFile = new StreamWriter"C:\\DebuggerLog.txt");
  28.             swLogFile.AutoFlush = true;
  29.                            string strInput,strOutput;
  30.             ProcessStartInfo psi = new ProcessStartInfo("C:\\MinGW\\bin\\gdb");
  31.  
  32.  
  33.  
  34.             psi.UseShellExecute = false;
  35.             psi.RedirectStandardInput = true;
  36.             psi.RedirectStandardError = true;
  37.  
  38.                                                 //Uncommenting the following line causes the process to crash whil starting.
  39.             //psi.RedirectStandardOutput = true;
  40.  
  41.             p.StartInfo = psi;
  42.             p.Start();
  43.             sw = p.StandardInput;
  44.             sw.AutoFlush = true;
  45.  
  46.             while(true)
  47.             {
  48.  
  49.             strInput = Console.ReadLine();
  50.             sw.WriteLine(strInput);
  51.             swLogFile.WriteLine(strInput);
  52.  
  53.                                 //               Cannot use following three lines as standard output for gdb cannot redirected above,
  54.         //    strOutput = p.StandardOutput.ReadToEnd();
  55.         //    Console.WriteLine(strOutput);
  56.         //    swLogFile.WriteLine(strOutput);
  57.  
  58.             if(strInput.Equals("quit"))
  59.             {
  60.                 swLogFile.Close();
  61.                 break;
  62.             }
  63.  
  64.         }
  65.     }
  66.     catch(Exception ex)
  67.     {
  68.         Console.WriteLine("The exception is : " + ex.Message);
  69.         Console.ReadLine();
  70.     }
  71.        }
  72.    }
  73. }
  74.  
Oct 11 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.