Server-side
1 2 3 4 5 6 7 8 | PS C:\> if ( $PSVersionTable .PSVersion.Major -eq 2) { Add -Type -AssemblyName System.Core } PS C:\> $pipe = New-Object System.IO.Pipes.NamedPipeServerStream( "\\.\pipe\MyPipeName" ) PS C:\> $pipe .WaitConnection() PS C:\> $writer = New-Object System.IO.BinaryWriter( $pipe ) PS C:\> [Byte[]] $data = 0x01, 0x02, 0x03, 0x04 PS C:\> $writer . Write ( $data ) PS C:\> $writer .Dispose() # Disconnect pipe PS C:\> |
Client-side
1 2 3 4 5 6 7 8 9 10 11 12 | PS C:\> if ( $PSVersionTable .PSVersion.Major -eq 2) { Add -Type -AssemblyName System.Core } PS C:\> $pipe = New-Object IO.Pipes.NamedPipeClientStream( '.' , 'MyPipeName' , [IO.Pipes.PipeDirection]::Out) PS C:\> $pipe .Connect() PS C:\> $reader = New-Object System.IO.BinaryReader( $pipe ) PS C:\> $data = $reader .ReadBytes(4) PS C:\> $data 1 2 3 4 PS C:\> $reader .Dispose() # Disconnect pipe PS C:\> |
Remark
.NET 3.5 이상 지원
References
- https://msdn.microsoft.com/en-us/library/system.io.pipes.namedpipeserverstream(v=vs.110).aspx
- https://msdn.microsoft.com/en-us/library/system.io.pipes.namedpipeclientstream(v=vs.110).aspx
- https://gbegerow.wordpress.com/2012/04/09/interprocess-communication-in-powershell/
- https://rkeithhill.wordpress.com/2014/11/01/windows-powershell-and-named-pipes/