Windows has no direct equivalent to /dev/stdout
.
Here is my attempt at writing a C# program that creates a named pipe, which can be given to program A as a filename. Requires .NET v4.
(C# because the compiler comes with .NET runtime, and what computer doesn't have .NET these days?)
PipeServer.cs
using System;
using System.IO;
using System.IO.Pipes;
class PipeServer {
static int Main(string[] args) {
string usage = "Usage: PipeServer <name> <in | out>";
if (args.Length != 2) {
Console.WriteLine(usage);
return 1;
}
string name = args[0];
if (String.Compare(args[1], "in") == 0) {
Pipe(name, PipeDirection.In);
}
else if (String.Compare(args[1], "out") == 0) {
Pipe(name, PipeDirection.Out);
}
else {
Console.WriteLine(usage);
return 1;
}
return 0;
}
static void Pipe(string name, PipeDirection dir) {
NamedPipeServerStream pipe = new NamedPipeServerStream(name, dir, 1);
pipe.WaitForConnection();
try {
switch (dir) {
case PipeDirection.In:
pipe.CopyTo(Console.OpenStandardOutput());
break;
case PipeDirection.Out:
Console.OpenStandardInput().CopyTo(pipe);
break;
default:
Console.WriteLine("unsupported direction {0}", dir);
return;
}
} catch (IOException e) {
Console.WriteLine("error: {0}", e.Message);
}
}
}
Compile with:
csc PipeServer.cs /r:System.Core.dll
csc
can be found in %SystemRoot%\Microsoft.NET\Framework64\<version>\csc.exe
For example, using .NET Client Profile v4.0.30319 on a 32-bit Windows XP:
"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\csc.exe" PipeServer.cs /r:System.Core.dll
Run:
PipeServer foo in | programtwo
in window one, and:
programone \\.\pipe\foo
in window two.