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?