Home All Groups Group Topic Archive Search About

Process - RedirectStandardInput

Author
15 Nov 2004 11:15 PM
phyzics

I have an old fortran console application that I am wrapping a UI around
(Windows.Forms).  I am using the method of launching the console app
described in the msdn article:
http://msdn.microsoft.com/msdnmag/issues/03/02/Multithreading/default.aspx

The fortran app recognizes a user pressed ESC keystroke to shut down nicely
(it is writing files etc...).  I need to be able to do the same and not just
kill the running process.

I have attempted to send the app the ESC key through StdIn (I am using MC++):


process = new Process;
process->StartInfo->UseShellExecute = false;
process->StartInfo->RedirectStandardInput = true;
process->StartInfo->RedirectStandardOutput = true;
process->StartInfo->RedirectStandardError = true;
process->StartInfo->CreateNoWindow = true;
process->StartInfo->FileName = "myfile";
process->StartInfo->Arguments = "myargs";
process->StartInfo->WorkingDirectory = "mydir";

process->Start();

MethodInvoker* thStdOut = new MethodInvoker(this, ReadStdOut) ;
MethodInvoker* thStdErr = new MethodInvoker(this, ReadStdErr) ;


//start reading StdOut and StdErr
thStdOut->BeginInvoke(NULL,NULL);
thStdErr->BeginInvoke(NULL,NULL);

.... do some work...

//send the escape key
StreamWriter *streamWriter = process->StandardInput;
    if(process != NULL)
    {
        char esc = (char)0x1b;
        streamWriter->Write(esc);
        streamWriter->Flush();
    }

but this does nothing to stop the console app.

I have also tried sending the escape key using SendKey like so:

System::Windows::Forms::SendKeys::Send("{ESC}");

but this also does nothing to stop the console app.



Any ideas or suggestions?

Thank you in advance

Bookmark and Share