I cannot directly open the process who's output I need. And there is no keyboard commands to highlight text in anyway.

I've found that I can find the process ID and create an object associated with that ID, but because I have to redirect the output upon initialization, I don't see a way to capture the output of this currently running process.

Is there anyway to get the output from the output stream of this process?

Here is some code I use in my program...I'm trying to put a line of the output into a textbox on my Windows Form upon button click.
**Please ignore all of the 'using' and 'dll imports' that are not used in the program, they are left over from experimentation

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace getOutput
{
    public partial class Form1 : Form
    {
        //Initializations and dll imports
        static int a = System.Diagnostics.Process.GetProcessesByName("processname.exe")[0].Id;
        
        Process process = Process.GetProcessById(a);  

        [DllImport("User32")]
        private static extern int ShowWindow(int hwnd, int nCmdShow);
        [DllImport("user32.dll")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll")]
        static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);


        public Form3()

        {                                                           //


            metasploit.StartInfo.UseShellExecute = false;
            metasploit.StartInfo.RedirectStandardOutput = true;

            

            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            //Creates a StreamReader, and reads the Standard Output of process
            StreamReader OutputReader = process.StandardOutput;
          //  Saves the Output to 'Output' and puts it in the textbox
            string Output = OutputReader.ReadLine();
            textBox1.Text = Output;          
        }

    }
}

Obviously this code doesn't work, and gives an error that the StandardOutput is not redirected.

In short....is there anyway to read the OutputStream of a currently running process?

>.is there anyway to read the OutputStream of a currently running process?

See this - http://www.daniweb.com/forums/thread94882.html

Take a look at a MSDN Page.

The problem is that they are STARTING the process with their codes. There is no way for me to start the process I need to read the output from because all I can open is a batch file that interweaves a few processes together. Starting the process alone won't work.

I need to know if I can read the output from a process that is already running before my program starts.

*I have also scoured MSDN and haven't found anything yet.

>I can read the output from a process that is already running before my program starts.

I think there is no simple way to do so.

This article has been dead for over six months. Start a new discussion instead.