Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
40 lines (35 loc) · 1.33 KB
/
Copy pathProgram.cs
File metadata and controls
40 lines (35 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RealtimeRedirection
{
class Program
{
static void Main(string[] args)
{
var processStartInfo = new ProcessStartInfo
{
FileName = @"G:\Sam\Documents\Source\Repos\StackOverflow\RealtimeRedirectionTest\bin\Debug\RealtimeRedirectionTest.exe",
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
};
var process = Process.Start(processStartInfo);
var automator = new ConsoleAutomator(process.StandardInput, process.StandardOutput);
// AutomatorStandardInputRead is your event handler
automator.StandardInputRead += Automator_StandardInputRead; ;
automator.StartAutomate();
// do whatever you want while that process is running
process.WaitForExit();
automator.StandardInputRead -= Automator_StandardInputRead;
process.Close();
}
private static void Automator_StandardInputRead(object sender, ConsoleInputReadEventArgs e)
{
Console.WriteLine($"Input: {e.Input}, size: {e.Input.Length}");
}
}
}