for instance
http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!1360.entry
--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk
Thank you.
There were several things I was doing wrong.
This should get anyone else started on the right foot.
There are async facilities that can be used too but the sync versions
show the timing dependencies better.
# This is the 3.5 assembly you need to load
[Reflection.Assembly]::LoadWithPartialName('System.Core')
# server side tasks
# A client connect will hang until a server side is created.
$a = new-object System.IO.Pipes.NamedPipeServerStream('TestPipe')
# This will hang until a client connects
$a.WaitForConnection()
# Create a byte array for input message
$msg = new-object byte[] 1000
# This will hang until client writes
$cnt=$sv.read($msg,0,$msg.count)
# Convert byte array back to string.
[string]::join('',[string[]][char[]]$msg[0..($cnt-1)])
# Client side tasks
$b = new-object System.IO.Pipes.NamedPipeClientStream('TestPipe')
# Connect hangs until a NamedPipeServerStream is created (above).
$b.connect()
# The message to send must be a byte array, not a string.
[byte[]]$txt=[char[]]'some message I want to send'
# The write will hang until the server reads it.
$rq.write($txt,0,$txt.count)
A broader answer: It can depend...
Example, from what I understand, you can use some of the features of
LINQ (.NET 3.5) directly from PowerShell. Also, until v2 CTP2, using
WPF (.NET 3.0) in PowerShell had issues.
Marco
--
*Microsoft MVP - Windows Server - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw
*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com
Thanks to both of you.
I never did get the async stuff to work.
Best I can tell, from reading various threads on async callbacks
in PowerShell, the async features are unuseable from PowerShell.
It seems that, theoretically, background jobs running the sync
versions should work. Before I spend hours trying, is this the
only way or is there a better way?
Hi Rick,
You seem to be a fairly technical guy - have you looked into CTP2's
eventing support?
http://blogs.msdn.com/powershell/archive/2008/06/11/powershell-eventing-quickstart.aspx
- Oisin
I've been meaning to look into that but forgot. Thanks. It turns it
may be very helpful to another project. I hope it works in our
environment. With all our machines being either XP or Server 2005 I
can't use jobs or runspaces under CTP2.
Unfortunately I couldn't figure out how eventing could help with named
pipes. The async features use methods that expect a callback
function. They don't create events I can subscribe to. Is there a
loophole? Register-ObjectEvent's -Action argument seems to have a way
around it.
Otherwise I'm hitting dead ends in each direction.
Hi RickB,
I'll show you how you can do this later this evening (EST). Keep an
eye on my blog ( www.nivot.org )
Hint: it involves using the Add-Type and Register-ObjectEvent cmdlets.
- Oisin
PowerShell MVP
http://www.nivot.org/
I guess you didn't have time (or I'm looking in the wrong place).
The hint didn't help much. Windows isn't my native platform so it
didn't go as far as it might for someone else. It doesn't help
that the commands are not documented either but I'm guessing that
your method will include a piece that starts like this.
add-type @"
using System;
...
But the implications are not landing on live brain cells.
I am actually beginning to wonder if the hints didn't help
because it's more complicated that it initially seemed.
If the solution is only evident to someone who has interfaced
with PowerShell from C#/VB.Net then it's obvious why I'm
not getting anywhere.