|
RE: Run tasks asynchronously: external files vs. script blocks >$StartInfo1 = new-object System.Diagnostics.ProcessStartInfo
That’s the way I did it before. :-)
Now consider following scenario:
Process A starts many B processes.
Each process B starts processes C and D.
Process A needs to track all of them and finally create timing report.
There are ways to do it, but (IMO!) using
[System.Management.Automation.Runspaces] is much more elegant with parameters
and results passing up and down the pipes.
About results from my example:
You should have TWO files in the same folder
f1.ps1
f2.ps1
you run f1.ps1 and it calls f2.ps1
the output I’m getting:
#1
################
CommandText ./f2.ps1
IsScript False
UseLocalScope False
1-- Value hello world parameter1: 10/30/2006 21:02:55 input: 10/30/2006
21:02:55 10/30/2006 21:02:55
################
I.e. in you case you not getting results back!
BTW: Is there a way to attach .zip to my post?
#2
################
CommandText param( [string] $p1) "hello world parameter1: $p1 input: $input"
IsScript True
UseLocalScope False
################
In the second case I can not get scriptblock to execute asynchronously.
And I can do it synchronously easily:
&$script $a
$a | &$script
################
hello world parameter1: 10/30/2006 21:08:26 input:
hello world parameter1: input: 10/30/2006
################
So the question remains open:
Is there a way to asynchronously execute a scriptblock?
(It’s rather theoretical, I use files anyway :-) |