Skip to content

Instantly share code, notes, and snippets.

@VisualMelon
Created December 2, 2015 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VisualMelon/f0c8adb7558fbc81b36f to your computer and use it in GitHub Desktop.
Save VisualMelon/f0c8adb7558fbc81b36f to your computer and use it in GitHub Desktop.
using System;
namespace StdioComms
{
class Program
{
public static void Main(string[] args)
{
if (args.Length > 0 && args[0] == "client")
{
// client
string line;
while ((line = Console.ReadLine()) != null)
{
Console.WriteLine(int.Parse(line) * 2);
}
}
else
{
// controller
string line;
var procStart = new System.Diagnostics.ProcessStartInfo("stdioComms.exe");
procStart.RedirectStandardInput = true;
procStart.RedirectStandardOutput = true;
procStart.Arguments = "client";
procStart.UseShellExecute = false;
var proc = System.Diagnostics.Process.Start(procStart);
var procWriter = proc.StandardInput;
var procReader = proc.StandardOutput;
while ((line = Console.ReadLine()) != null)
{
procWriter.WriteLine(line);
Console.WriteLine(procReader.ReadLine());
}
proc.Kill();
}
}
}
}
@VisualMelon
Copy link
Author

When run, it spawns a new client process, which it then passes input to, and writes output from, synchronously. The effect is that you have a unnecessarily complicated terminal which doubles any integer you plug in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment