Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
36 lines (34 loc) · 1.38 KB
/
Copy pathProgram.cs
File metadata and controls
36 lines (34 loc) · 1.38 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
using System;
using System.Diagnostics;
// # - ProcessStartInfo hanging on "WaitForExit"? Why? - Stack Overflow
// https://stackoverflow.com/questions/139593/processstartinfo-hanging-on-waitforexit-why
namespace WaitForExitHangs
{
class Program
{
static void Main(string[] args)
{
const string TheProgram = @"G:\Sam\Documents\Source\Repos\StackOverflow\WaitForExitHangsTest\bin\Debug\WaitForExitHangsTest.exe";
Process OurProcess = Process.GetCurrentProcess();
Console.WriteLine($"Our process is {OurProcess.Id} {OurProcess.ProcessName}");
ProcessStartInfo info = new ProcessStartInfo(TheProgram);
info.CreateNoWindow = true;
info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
Process p = Process.Start(info);
Console.WriteLine($"Process {p.Id} {p.ProcessName}");
int datasize = 0;
string record = p.StandardOutput.ReadLine();
while (record != null)
{
datasize += record.Length + 2;
Console.WriteLine(record);
record = p.StandardOutput.ReadLine();
}
p.WaitForExit();
string counts = $"{datasize}";
Console.WriteLine(datasize);
}
}
}