Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在无窗口命令行上模拟击键_C#_Signals_Keystroke - Fatal编程技术网

C# 如何在无窗口命令行上模拟击键

C# 如何在无窗口命令行上模拟击键,c#,signals,keystroke,C#,Signals,Keystroke,我在将击键传递到无窗口命令行时遇到问题 我按照以下步骤启动流程: public partial class BatchRun : Form { public void StartProcess(Process name) { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = sMasterBATname; start

我在将击键传递到无窗口命令行时遇到问题

我按照以下步骤启动流程:

  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是一个批处理文件,其中包含许多要执行的exe命令。每个exe行后面都有一个暂停。这是必要的,因为我需要验证被重定向的每一行,有时exe执行得太快,我没有时间检查它是否出错

输出重定向到部分类,如下所示

 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. 
       } 
     }  
    }
 }
我做了一些研究,但没有找到对我有用的。我所能找到的只是我需要把窗口打开或传递消息等,但似乎不起作用

请有人帮我解释一下,就像我是一个6岁的孩子一样


希望这是有意义的

你能使用过程的标准输出属性吗。这是一个StreamWriter,你可以对它进行WriteLines,Hanks Alex。你能给我指一个例子的方向吗。第二个答案启动cmd并写入cmd的标准outputGreat。再次感谢。都分类好了。这么简单。。。