Process.RedirectStandardInput Question

  • Thread starter Thread starter Matt Osborne
  • Start date Start date
M

Matt Osborne

Hello all.

I have an application that i am writing to automate an older system. The
system is based on a 16-bit DOS application. It apears to me that I am
unable to redirect input and output to and from the application. Does
anybody know if i am missing something simple?

Thanks
 
Sorry, here is the code

ProcessStartInfo startInfo = new ProcessStartInfo( "snap2.pif", "" );
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;

Thread.Sleep( 1000 );

Process snapToIt = Process.Start( startInfo );

StreamWriter writer = snapToIt.StandardInput;
StreamReader reader = snapToIt.StandardOutput;

writer = new StreamWriter( writer.BaseStream, new
System.Text.ASCIIEncoding() );

writer.AutoFlush = true;
writer.Write( (byte)'x' );
writer.Write( (byte)'x' );
writer.Write( (byte)'x' );
writer.Write( (byte)'x' );
writer.Write( (byte)13 );
writer.Write( (byte)'s' );
writer.Write( (byte)'i' );
writer.Write( (byte)'=' );
writer.Write( (byte)'p' );
writer.Write( (byte)'r' );
writer.Write( (byte)'o' );
writer.Write( (byte)'d' );
writer.Write( (byte)13 );
writer.Write( (byte)13 );
writer.Write( (char)121 );

As you can see i have tried using bytes instead of chars to be "more 16 bit
compliant" but to no avail. I also have tried changing the formatter to be
ascii and that hasn't helped.

Thanks for the help
 
Try this

pDOSProcess.StartInfo.RedirectStandardOutput = true;
pDOSProcess.StartInfo.CreateNoWindow = true;
pDOSProcess.EnableRaisingEvents = true;
pDOSProcess.StartInfo.UseShellExecute = false;
//Add the exited event
pDOSProcess.Exited += new EventHandler(Process_exited);

pDOSProcess.Start();


private void Process_exited(object sender, System.EventArgs ea)
{
Process pro = (Process)sender;
//get the output.
string stdout= pro.StandardOutput.ReadToEnd();
}
 
Thanks for your post.

I tried your suggestion to no avail. To let you know more, I tried what i
had spawning "cmd" instead of my target app and i get a console window with
no output and i am able to read and write to its standard input and output
with out any problems. With this app I still can see the out put and it
apears that it is not recieving any input and when i manualy try to input
data it does not work either.

Any Ideas? The only think i can think of is that it doesn't work on 16 bit
applications
 
Back
Top