You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.3 KiB
48 lines
1.3 KiB
using System;
|
|
using System.Diagnostics;
|
|
|
|
namespace PipeTest
|
|
{
|
|
class Parent
|
|
{
|
|
private static bool Test(long size)
|
|
{
|
|
Console.WriteLine($"Testing: {size}");
|
|
bool result = true;
|
|
using (var p = new Process())
|
|
{
|
|
p.StartInfo.FileName = @".\Child.exe";
|
|
p.StartInfo.Arguments = size.ToString();
|
|
p.StartInfo.RedirectStandardOutput = true;
|
|
if (! p.Start()) throw new Exception("子プロセス開始失敗");
|
|
if (!p.WaitForExit(2000))
|
|
{
|
|
result = false;
|
|
p.Kill();
|
|
}
|
|
//Console.Write(p.StandardOutput.ReadToEnd());
|
|
}
|
|
Console.WriteLine($"Result: {result}");
|
|
return result;
|
|
}
|
|
static void Main(string[] args)
|
|
{
|
|
long size = 1;
|
|
while (Test(size)) size *= 2;
|
|
var max = size;
|
|
var min = size / 2;
|
|
while (min + 1 < max)
|
|
{
|
|
size = (min + max) / 2;
|
|
if (Test(size))
|
|
{
|
|
min = size;
|
|
} else
|
|
{
|
|
max = size;
|
|
}
|
|
}
|
|
Console.WriteLine($"size of buffer: {min}");
|
|
}
|
|
}
|
|
}
|