From c9d6c75e0535b973123b661af992a83915acc55a Mon Sep 17 00:00:00 2001 From: icedream Date: Tue, 30 Apr 2013 02:43:09 +0200 Subject: [PATCH] Initial commit --- .gitignore | 3 ++ compile-pipeserver.bat | 2 + npipe.sln | 20 ++++++++++ npipe/Program.cs | 65 ++++++++++++++++++++++++++++++++ npipe/Properties/AssemblyInfo.cs | 36 ++++++++++++++++++ npipe/npipe.csproj | 50 ++++++++++++++++++++++++ 6 files changed, 176 insertions(+) create mode 100644 .gitignore create mode 100644 compile-pipeserver.bat create mode 100644 npipe.sln create mode 100644 npipe/Program.cs create mode 100644 npipe/Properties/AssemblyInfo.cs create mode 100644 npipe/npipe.csproj diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..48a3f58 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/npipe/bin +/npipe/obj +/*.suo diff --git a/compile-pipeserver.bat b/compile-pipeserver.bat new file mode 100644 index 0000000..b489c95 --- /dev/null +++ b/compile-pipeserver.bat @@ -0,0 +1,2 @@ +"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\csc.exe" /optimize+ /debug- /nowin32manifest /target:exe /out:npipe.exe npipe\Program.cs npipe\Properties\AssemblyInfo.cs /r:System.Core.dll +pause \ No newline at end of file diff --git a/npipe.sln b/npipe.sln new file mode 100644 index 0000000..adc1085 --- /dev/null +++ b/npipe.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "npipe", "npipe\npipe.csproj", "{404896DF-481E-4747-9173-74174FA76F34}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {404896DF-481E-4747-9173-74174FA76F34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {404896DF-481E-4747-9173-74174FA76F34}.Debug|Any CPU.Build.0 = Debug|Any CPU + {404896DF-481E-4747-9173-74174FA76F34}.Release|Any CPU.ActiveCfg = Release|Any CPU + {404896DF-481E-4747-9173-74174FA76F34}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/npipe/Program.cs b/npipe/Program.cs new file mode 100644 index 0000000..3c6fd99 --- /dev/null +++ b/npipe/Program.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Diagnostics; +using System.IO.Pipes; + +namespace npipe +{ + class Program + { + static void Main(string[] args) + { + if (args.Count() < 2) + { Usage(); return; } + + switch (args.First().ToLower()) + { + case "server": + { + try + { + NamedPipeServerStream pipe = new NamedPipeServerStream(args.Last(), PipeDirection.Out, 1); + pipe.WaitForConnection(); + using (var stdin = Console.OpenStandardInput()) + { + stdin.CopyTo(pipe); + } + } + catch (Exception) + { + return; + } + } + break; + case "client": + { + try + { + NamedPipeClientStream pipe = new NamedPipeClientStream(".", args.Last(), PipeDirection.In); + pipe.Connect(); + using (var stdout = Console.OpenStandardOutput()) + { + pipe.CopyTo(stdout); + } + } + catch (Exception) + { + return; + } + } + break; + } + } + + static void Usage() + { + Console.WriteLine("Usage:"); + Console.WriteLine("\t" + Process.GetCurrentProcess().ProcessName + " "); + Console.WriteLine(); + Console.WriteLine("Modes:"); + Console.WriteLine("\tserver\tMakes data available via a pipe. Writes to pipe from stdin."); + Console.WriteLine("\tclient\tMakes data available from a pipe. Reads from pipe to stdout."); + } + } +} diff --git a/npipe/Properties/AssemblyInfo.cs b/npipe/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e9ed033 --- /dev/null +++ b/npipe/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die mit einer Assembly verknüpft sind. +[assembly: AssemblyTitle("npipe")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Carl Kittelberger")] +[assembly: AssemblyProduct("npipe")] +[assembly: AssemblyCopyright("© 2013 Carl Kittelberger")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar +// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von +// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("dad89c06-6c66-4e29-8ed1-11635c77f54d")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern +// übernehmen, indem Sie "*" eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyFileVersion("1.0")] diff --git a/npipe/npipe.csproj b/npipe/npipe.csproj new file mode 100644 index 0000000..89b55a7 --- /dev/null +++ b/npipe/npipe.csproj @@ -0,0 +1,50 @@ + + + + + Debug + AnyCPU + {404896DF-481E-4747-9173-74174FA76F34} + Exe + Properties + npipe + npipe + v4.0 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + \ No newline at end of file