473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Gow to redirect output from gdb.exe in C#

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
0 1882

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

Similar topics

5
by: Hal Vaughan | last post by:
I have a Java program, composed of a number of classes, that I've been running as a command line program. It logs everything it does and, as it logs each event, it also prints that line of info to...
6
by: Tim Stokes | last post by:
Hi all, I want to do a similar action to response.redirect ("file.htm"). But the file.htm contains some sensitive data. I have placed file.htm in a folder in the InetPub...
7
by: Donna Hawkins | last post by:
I want to use javascript to redirect to a URL which has been passed as a variable (in php). I have searched but cannot find any solution. I think this code is a basic redirect: <script...
2
by: Jason | last post by:
Hello, I have a class, transCore, that does certain work, and by default, prints its progress to the stand output. Later, I will to write a GUI class that encapsulate the transCore class. I...
1
by: Byron | last post by:
I want to take the output of a DOS console application that just streams data to the screen and redirect that output in real time into a C# application that will decode and reformat it for display....
1
by: Peter Kirk | last post by:
Hi there I have a program written by another company (it's a "web control" which returns a web-page: can I compare this to a servlet in the Java world?), which they think is causing problems on...
8
by: Andreas Klemt | last post by:
Hello, I get this error Message "cannot redirect after http headers have been sent" when I do this response.redirect ("home.aspx") How can I find out with vb.net if already a http header has...
6
by: cmk128 | last post by:
Hi here is my c file, compile in gcc 3.X in linux: #include <stdio.h> int main() { printf("Hello\n"); if (fork() == 0) printf("world! \n"); }
18
by: Jordan Glassman | last post by:
Trying to do something fairly routine... drop output into a file to graph, but the following command at the bash command line: ising output produces a blinking cursor, an empty file named...
18
by: Paul Lautman | last post by:
JRough wrote: What do you mean by "redirect the output to Excel"??? Excel isn't a location, it's a spreadsheet program that some (but not all users) will have on their machine. BTW, Location:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.