0

I'm having trouble with passing a keystroke into a windowless command line.

I start the process as per below:

  public partial class BatchRun : Form
{        
    public void StartProcess(Process name)
    {
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.FileName = sMasterBATname;
        startInfo.UseShellExecute = false;
        startInfo.CreateNoWindow = true;
        startInfo.RedirectStandardOutput = true;
        name.StartInfo = startInfo;
        name.OutputDataReceived += new DataReceivedEventHandler(StandardOutputHandler);
        name.StartInfo.RedirectStandardInput = true;
        name.Start();
        name.BeginOutputReadLine();
    }
}

sMasterBATfile is a batch file which contains number of exe commands to execute. Each exe line is followed by a pause. This is necessary as I need to validate each line which is being redirected and sometimes exe is executed so quickly I have no time to check if it errored or not.

Output is redirected to partial class as per below.

 public partial class BatchRun : Form
{
    public void outLineValidation(string text)
    {
     if (text != null && !String.IsNullOrWhiteSpace(text))
     {
      if (text.Contains("Critical error") || text.Contains("Fatal error"))
       {
              Do something 
       }
      else if (text.Contains("Complete run time"))
       {
         This is where I need to pass or 
         simulate a keystroke to be passed to the process that executes 
         exe files so that next exe can be executed. 
       } 
     }  
    }
 }

I did some research but could not find any that was working for me. All I could find was that I need to bring window forward or pass message etc but not seems to be working.

Could someone help please and explain as if I was a 6 year old please.

Hope this makes sense.

TomTommyTom
  • 113
  • 1
  • 2
  • 11
  • Can you use the StandartOutput propery of the process. It is a StreamWriter and you can do WriteLines to it – Alex Jul 04 '17 at 07:17
  • Thanks Alex. Could you point me in the direction of an example please. – TomTommyTom Jul 04 '17 at 07:20
  • https://stackoverflow.com/questions/437419/execute-multiple-command-lines-with-the-same-process-using-net the second answer launches cmd and writes to cmd's standard output – Alex Jul 04 '17 at 07:30
  • Great. Thanks again. all Sorted. So simple... – TomTommyTom Jul 04 '17 at 07:40

0 Answers0