Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I Start a job of a function i just defined?

Tags:

How do I Start a job of a function i just defined?

function FOO { write-host "HEY" } Start-Job -ScriptBlock { FOO } | Receive-Job  Receive-Job: The term 'FOO' is not recognized as the name of cmdlet, function ,script file or operable program. 

What do I do? Thanks.

like image 557
Alex58 Avatar asked Aug 23 '11 13:08

Alex58


1 Answers

As @Shay points out, FOO needs to be defined for the job. Another way to do this is to use the -InitializationScript parameter to prepare the session.

For your example:

$functions = {     function FOO { write-host "HEY" } }  Start-Job -InitializationScript $functions -ScriptBlock {FOO}|     Wait-Job| Receive-Job 

This can be useful if you want to use the same functions for different jobs.

like image 58
Rynant Avatar answered Sep 20 '22 23:09

Rynant