75 lines
1.7 KiB
C#
75 lines
1.7 KiB
C#
// See https://aka.ms/new-console-template for more information
|
|
using System.Diagnostics;
|
|
|
|
int lineCount = 0;
|
|
|
|
|
|
void OutputHandler(object sender, DataReceivedEventArgs e)
|
|
{
|
|
if (!string.IsNullOrEmpty(e.Data))
|
|
{
|
|
Console.WriteLine($"RIPOSTA PROCESSO [{lineCount}] - {e.Data}");
|
|
if (e.Data == "SUCCESS")
|
|
{
|
|
lineCount += 1;
|
|
}
|
|
}
|
|
};
|
|
|
|
var domanda = "Sai chi ti saluta tantissimo?";
|
|
|
|
Console.WriteLine(domanda);
|
|
|
|
// Create a new process object
|
|
Process p = new Process();
|
|
|
|
// Specify the file name of the external exe
|
|
p.StartInfo.FileName = @"C:\Temp\TestEcho.bat";
|
|
p.StartInfo.UseShellExecute = false;
|
|
p.StartInfo.RedirectStandardOutput = true;
|
|
p.StartInfo.RedirectStandardInput = true;
|
|
//var stdIn = p.StandardInput;
|
|
p.OutputDataReceived += (s, e) => OutputHandler(s, e);
|
|
|
|
// Optionally, specify any arguments for the exe
|
|
//p.StartInfo.Arguments = domanda;
|
|
|
|
// Start the process
|
|
p.Start();
|
|
|
|
p.StandardInput.WriteLine(domanda);
|
|
|
|
p.BeginOutputReadLine();
|
|
|
|
while (!p.HasExited)
|
|
{
|
|
//Console.WriteLine(output.ToString());
|
|
Thread.Sleep(500);
|
|
//var inVar = Console.ReadLine();
|
|
//// mando nuovo input...
|
|
//p.StandardInput.WriteLine(domanda);
|
|
Thread.Sleep(500);
|
|
// mando nuovo input...
|
|
p.StandardInput.WriteLine(domanda);
|
|
Thread.Sleep(500);
|
|
// mando nuovo input...
|
|
p.StandardInput.WriteLine(domanda);
|
|
Thread.Sleep(500);
|
|
// mando nuovo input...
|
|
p.StandardInput.WriteLine(domanda);
|
|
Thread.Sleep(500);
|
|
// mando nuovo input...
|
|
p.StandardInput.WriteLine("escape");
|
|
}
|
|
|
|
|
|
// Optionally, wait for the process to exit
|
|
p.WaitForExit();
|
|
|
|
|
|
p.Close();
|
|
|
|
Console.WriteLine("Ho finito...");
|
|
Console.WriteLine("...press return to close");
|
|
|
|
Console.ReadLine(); |