Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Running an external process asynchronously

Reply
 
Old 05-14-2008   #1 (permalink)
Romu


 
 

Running an external process asynchronously

Hi all,
All the question is in the title;

I need to run an external process from my powershell script asynchronously,
I want powershell to continue my script execution as soon as this process is
started.

Any idea?

Thanks in advance

My System SpecsSystem Spec
Old 05-14-2008   #2 (permalink)
Marco Shaw [MVP]


 
 

Re: Running an external process asynchronously

Romu wrote:
Quote:

> Hi all,
> All the question is in the title;
>
> I need to run an external process from my powershell script asynchronously,
> I want powershell to continue my script execution as soon as this process is
> started.
>
> Any idea?
>
> Thanks in advance
PowerShell v1:
http://jtruher.spaces.live.com/blog/...628D!130.entry

PowerShell v2 CTP1/CTP2:
get-help start-psjob

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 05-14-2008   #3 (permalink)
Keith Hill [MVP]


 
 

Re: Running an external process asynchronously

"Romu" <Romu@xxxxxx> wrote in message
news:26878AEF-39AC-412F-96A3-5BB7775BC0B0@xxxxxx
Quote:

> Hi all,
> All the question is in the title;
>
> I need to run an external process from my powershell script
> asynchronously,
> I want powershell to continue my script execution as soon as this process
> is
> started.
>
> Any idea?
>
If you are willing to give the PowerShell Community Extensions a try, you
can use Start-Process like so:

foo.ps1
--------
echo "Before"
Start-Process csc.exe -arg '/?' -noshellexecute
echo "!!!!! After !!!!!"

--
Keith Hill
http://www.codeplex.com/powershellcx

My System SpecsSystem Spec
Old 05-15-2008   #4 (permalink)
Romu


 
 

Re: Running an external process asynchronously

Many thanks guys,
Indeed I just realized that the thing I need to call asynchronously is a
powershell function of my own.

An example :
#The function
function Synchronise(computername)
{
....
}


#The script
Synchronise(PC1)
Synchronise(PC2)
Synchronise(LINUX1)
Synchronise(MAC1)


My function Synchronise is called several times and I need to run
asynchronously. This function is used to synchronise a set of files and
folders on computers and it's called several times because we synchronise
several computers.

I would like to see the script to continue once the synchronisation is
launched.

Thanks in advance for your help.

romu

"Keith Hill [MVP]" wrote:
Quote:

> "Romu" <Romu@xxxxxx> wrote in message
> news:26878AEF-39AC-412F-96A3-5BB7775BC0B0@xxxxxx
Quote:

> > Hi all,
> > All the question is in the title;
> >
> > I need to run an external process from my powershell script
> > asynchronously,
> > I want powershell to continue my script execution as soon as this process
> > is
> > started.
> >
> > Any idea?
> >
>
> If you are willing to give the PowerShell Community Extensions a try, you
> can use Start-Process like so:
>
> foo.ps1
> --------
> echo "Before"
> Start-Process csc.exe -arg '/?' -noshellexecute
> echo "!!!!! After !!!!!"
>
> --
> Keith Hill
> http://www.codeplex.com/powershellcx
>
My System SpecsSystem Spec
Old 05-15-2008   #5 (permalink)
Marco Shaw [MVP]


 
 

Re: Running an external process asynchronously

Romu wrote:
Quote:

> Many thanks guys,
> Indeed I just realized that the thing I need to call asynchronously is a
> powershell function of my own.
>
> An example :
> #The function
> function Synchronise(computername)
> {
> ...
> }
>
>
> #The script
> Synchronise(PC1)
> Synchronise(PC2)
> Synchronise(LINUX1)
> Synchronise(MAC1)
>
>
> My function Synchronise is called several times and I need to run
> asynchronously. This function is used to synchronise a set of files and
> folders on computers and it's called several times because we synchronise
> several computers.
Yup, the solutions Keith and I proposed could be embedded within your
functions. The only thing not evident to me (this early in the morning
;-)) is if you expected to somehow return the results from the function.

I can't think of another easier way for you to attempt what you want.

Marco
My System SpecsSystem Spec
Old 05-15-2008   #6 (permalink)
Romu


 
 

Re: Running an external process asynchronously

Thanks for quick answer Marco,
No the function doesn't return any result, it is just a "run and forget"
function.

And I can't make the inside aynchronous as the actions performed by the
function must be sequential. So the whole function must be aynschronous.

"Marco Shaw [MVP]" wrote:
Quote:

> Romu wrote:
Quote:

> > Many thanks guys,
> > Indeed I just realized that the thing I need to call asynchronously is a
> > powershell function of my own.
> >
> > An example :
> > #The function
> > function Synchronise(computername)
> > {
> > ...
> > }
> >
> >
> > #The script
> > Synchronise(PC1)
> > Synchronise(PC2)
> > Synchronise(LINUX1)
> > Synchronise(MAC1)
> >
> >
> > My function Synchronise is called several times and I need to run
> > asynchronously. This function is used to synchronise a set of files and
> > folders on computers and it's called several times because we synchronise
> > several computers.
>
> Yup, the solutions Keith and I proposed could be embedded within your
> functions. The only thing not evident to me (this early in the morning
> ;-)) is if you expected to somehow return the results from the function.
>
> I can't think of another easier way for you to attempt what you want.
>
> Marco
>
My System SpecsSystem Spec
Old 05-15-2008   #7 (permalink)
Marco Shaw [MVP]


 
 

Re: Running an external process asynchronously

Romu wrote:
Quote:

> Thanks for quick answer Marco,
> No the function doesn't return any result, it is just a "run and forget"
> function.
>
> And I can't make the inside aynchronous as the actions performed by the
> function must be sequential. So the whole function must be aynschronous.
Perhaps Keith and I are missing something... First, what solution are
you willing/wanting to try out, and we will go from there:

#1: v1: Use Jim's background jobs.
#2: v1/v2 CTP: Use Keith's PSCX.
#3: v2 CTP: Use *-PSJobs

If in a prod environment, and you can't go installing 3rd party
PowerShell add-ons, then it seems #1 is your option. It is just some
PowerShell scripts that use existing functionality provided by
PowerShell v1.

Marco
My System SpecsSystem Spec
Old 05-15-2008   #8 (permalink)
Romu


 
 

Re: Running an external process asynchronously

Thanks Marco,
I've just taken a look at the jim's background jobs and I think this is what
I need.

Thanks for your help.

"Marco Shaw [MVP]" wrote:
Quote:

> Romu wrote:
Quote:

> > Thanks for quick answer Marco,
> > No the function doesn't return any result, it is just a "run and forget"
> > function.
> >
> > And I can't make the inside aynchronous as the actions performed by the
> > function must be sequential. So the whole function must be aynschronous.
>
> Perhaps Keith and I are missing something... First, what solution are
> you willing/wanting to try out, and we will go from there:
>
> #1: v1: Use Jim's background jobs.
> #2: v1/v2 CTP: Use Keith's PSCX.
> #3: v2 CTP: Use *-PSJobs
>
> If in a prod environment, and you can't go installing 3rd party
> PowerShell add-ons, then it seems #1 is your option. It is just some
> PowerShell scripts that use existing functionality provided by
> PowerShell v1.
>
> Marco
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Monitor is a process is running PowerShell
iexplore running as process Vista General
How can I get information about running process? PowerShell
Unknown Running Process Vista security
Run tasks asynchronously: external files vs. script blocks PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46