Click here to Skip to main content
15,908,437 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to redirect WriteFile func writes to console Pin
leon de boer18-Feb-18 22:45
leon de boer18-Feb-18 22:45 
GeneralRe: How to redirect WriteFile func writes to console Pin
Łukasz Gęsieniec19-Feb-18 0:34
Łukasz Gęsieniec19-Feb-18 0:34 
GeneralRe: How to redirect WriteFile func writes to console Pin
leon de boer19-Feb-18 5:48
leon de boer19-Feb-18 5:48 
GeneralRe: How to redirect WriteFile func writes to console Pin
leon de boer19-Feb-18 6:19
leon de boer19-Feb-18 6:19 
GeneralRe: How to redirect WriteFile func writes to console Pin
Łukasz Gęsieniec19-Feb-18 9:06
Łukasz Gęsieniec19-Feb-18 9:06 
GeneralRe: How to redirect WriteFile func writes to console Pin
Łukasz Gęsieniec19-Feb-18 19:53
Łukasz Gęsieniec19-Feb-18 19:53 
GeneralRe: How to redirect WriteFile func writes to console Pin
leon de boer19-Feb-18 20:14
leon de boer19-Feb-18 20:14 
GeneralRe: How to redirect WriteFile func writes to console Pin
Łukasz Gęsieniec19-Feb-18 22:34
Łukasz Gęsieniec19-Feb-18 22:34 
I do simple test and problem is the same as before. Only when console app quits OutputHandler is executed and then I can read every line by line that app prints during running. Furthermore, it seems that StandardInput is not redirected because click on the button does not quit the app. App quits when 'e' key is pressed in the console window.
C#
public partial class MainWindow : Window
{
    Process process = new Process();

    public MainWindow()
    {
        InitializeComponent();
        runCommand();
    }

    private void button_Click(object sender, RoutedEventArgs e)
    {
        textBox.Text += "test\r\n";
        process.StandardInput.Write('e');
    }

    void runCommand()
    {
        //* Create your Process

        process.StartInfo.FileName = "c:\\ConsoleApp.exe";
        process.StartInfo.Arguments = ".";
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardError = true;
        process.StartInfo.RedirectStandardInput = true;
        //* Set your output and error (asynchronous) handlers
        process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
        process.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler);

        //* Start process and handlers
        process.Start();
        process.BeginOutputReadLine();
        process.BeginErrorReadLine();
        //            process.WaitForExit();
    }
    void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
    {
        //* Do your stuff with the output (write to console/log/StringBuilder)
        Console.WriteLine(outLine);
    }
}

GeneralRe: How to redirect WriteFile func writes to console Pin
leon de boer20-Feb-18 6:18
leon de boer20-Feb-18 6:18 
GeneralRe: How to redirect WriteFile func writes to console Pin
leon de boer20-Feb-18 6:33
leon de boer20-Feb-18 6:33 
GeneralRe: How to redirect WriteFile func writes to console Pin
Łukasz Gęsieniec20-Feb-18 23:32
Łukasz Gęsieniec20-Feb-18 23:32 
GeneralRe: How to redirect WriteFile func writes to console Pin
leon de boer21-Feb-18 7:12
leon de boer21-Feb-18 7:12 
GeneralRe: How to redirect WriteFile func writes to console Pin
Łukasz Gęsieniec21-Feb-18 19:57
Łukasz Gęsieniec21-Feb-18 19:57 
GeneralRe: How to redirect WriteFile func writes to console Pin
leon de boer22-Feb-18 14:19
leon de boer22-Feb-18 14:19 
GeneralRe: How to redirect WriteFile func writes to console Pin
Łukasz Gęsieniec22-Feb-18 19:50
Łukasz Gęsieniec22-Feb-18 19:50 
GeneralRe: How to redirect WriteFile func writes to console Pin
Peter_in_278022-Feb-18 20:21
professionalPeter_in_278022-Feb-18 20:21 
GeneralRe: How to redirect WriteFile func writes to console Pin
leon de boer22-Feb-18 21:06
leon de boer22-Feb-18 21:06 
Questionproblem defining a function inside a structure in c Pin
Member 1367832014-Feb-18 5:40
Member 1367832014-Feb-18 5:40 
AnswerRe: problem defining a function inside a structure in c Pin
David Crow14-Feb-18 6:09
David Crow14-Feb-18 6:09 
AnswerRe: problem defining a function inside a structure in c Pin
CPallini14-Feb-18 10:44
mveCPallini14-Feb-18 10:44 
Questionsetting Boundary condition X^2-Y^2 for solving Laplace equation for NxN grid. Pin
Member 1362564310-Feb-18 17:23
Member 1362564310-Feb-18 17:23 
AnswerRe: setting Boundary condition X^2-Y^2 for solving Laplace equation for NxN grid. Pin
Victor Nijegorodov10-Feb-18 23:07
Victor Nijegorodov10-Feb-18 23:07 
QuestionDefault Stack Size Pin
ForNow10-Feb-18 17:02
ForNow10-Feb-18 17:02 
AnswerRe: Default Stack Size Pin
Richard MacCutchan10-Feb-18 21:23
mveRichard MacCutchan10-Feb-18 21:23 
GeneralRe: Default Stack Size Pin
ForNow11-Feb-18 3:55
ForNow11-Feb-18 3:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.