I want to read output from a child process in console mode

I am trying to update a program written in 1995 using pascal or c. I am not sure about the programming language. Command line program. Now I am encoded in C #. And I want to read the exit from the children's program. Is it possible?

I tried something. But failed. It:

    private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
    {
        // Redirect the output stream of the child process.
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.FileName = "asdd.exe";
        p.Start();


        logs.AppendText("Timer Started\n");
        timer1.Enabled = true;


    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        // write somethingg and read what is the program doing on command line?
        // What is the program printint? etc... 
        // I try this code but not enough for mo. 
        // logs.AppendText("d:" + p.StandardOutput.ReadToEnd()+"\n");

    }

    private void p_Exited(object sender, EventArgs e)
    {
        timer1.Enabled = false;
    }

I am open to any ideas in java, cpp, c or C #.

Edit:

For instance:

My source code for asdd.exe

#include<stdio.h>

int main(){
    printf("something\n");
    printf("something, too\n");
}

This C # softkey and richTextBox logs are added using:

something
something, too
+3
source share
4 answers

ReadToEnd . , , .

0

This is how I usually read from a separate process. Now this will block the current thread until processing is complete, so I use a background thread.

process.StartInfo.FileName = "program.exe"
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

process.Start();

process.StandardInput.WriteLine(data);

string result = process.StandardOutput.ReadToEnd();

process.WaitForExit();
0
source

This MSDN article seems to be exactly what you are looking for.

Creating a child process with redirected inputs and outputs

0
source

All Articles