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:
-
using System;
-
using System.IO;
-
using System.Diagnostics;
-
-
namespace TeeBetweenGDBAndIDE
-
{
-
/// <summary>
-
/// Summary description for Class1.
-
/// </summary>
-
class Class1
-
{
-
/// <summary>
-
/// The main entry point for the application.
-
/// </summary>
-
[STAThread]
-
static void Main(string[] args)
-
{
-
//
-
// TODO: Add code to start application here
-
//
-
try
-
{
-
Process p = new Process();
-
StreamWriter sw;
-
-
-
StreamWriter swLogFile = new StreamWriter"C:\\DebuggerLog.txt");
-
swLogFile.AutoFlush = true;
-
string strInput,strOutput;
-
ProcessStartInfo psi = new ProcessStartInfo("C:\\MinGW\\bin\\gdb");
-
-
-
-
psi.UseShellExecute = false;
-
psi.RedirectStandardInput = true;
-
psi.RedirectStandardError = true;
-
-
//Uncommenting the following line causes the process to crash whil starting.
-
//psi.RedirectStandardOutput = true;
-
-
p.StartInfo = psi;
-
p.Start();
-
sw = p.StandardInput;
-
sw.AutoFlush = true;
-
-
while(true)
-
{
-
-
strInput = Console.ReadLine();
-
sw.WriteLine(strInput);
-
swLogFile.WriteLine(strInput);
-
-
// Cannot use following three lines as standard output for gdb cannot redirected above,
-
// strOutput = p.StandardOutput.ReadToEnd();
-
// Console.WriteLine(strOutput);
-
// swLogFile.WriteLine(strOutput);
-
-
if(strInput.Equals("quit"))
-
{
-
swLogFile.Close();
-
break;
-
}
-
-
}
-
}
-
catch(Exception ex)
-
{
-
Console.WriteLine("The exception is : " + ex.Message);
-
Console.ReadLine();
-
}
-
}
-
}
-
}
-