I have written two programs to test some stdin/stdout redirection ideas to
eventually test a legacy console application writtn in C.
One of the programs is a simple console app with some Console::WriteLine's
and printf to write to the console, and gets to read from stdin. This
program works correctly when run standalone.
The second program is a small Windows form that launches the first app and
redirects stdin and stdout to itself so the outputs of the first app can be
displayed on the form.
This is the problem. I use
dllTest->StandardInput->WriteLine("Writeline Test");
textBox6->Text = dllTest->StandardOutput->ReadLine();
in my second program to write to the first program, then display what was
written.
In the first (console) program, I use
char s[80];
printf("This is a Test2\n");
fflush(stdout);
//scanf("%32s");
gets(s);
printf("s%s\n", s);
This works correctly, sending "This is a Test2\n" to my Windows form to be
displayed. But if I comment out the fflush line, or use the scanf line with
or without fflush, the console program freezes and nothing is sent to the
windows program. If I then close the console program, the printf's before
the scanf or gets get sent to the Windows form, but the scanf or gets don't
send its output.
So what is the fflush(stdout) doing here?
And does anyone know if there is a way to get the scanf to work, possibly by
flushing from the second (Windows) program. That way my legacy program
wouldn't have to be rewritten.
Thanks.
Chuck