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

后端 未结 7 809
臣服心动
臣服心动 2020-11-27 23:34

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 \'         


        
7条回答
  •  攒了一身酷
    2020-11-27 23:51

    A slightly different take. A function is just a scriptblock assigned to a variable. Oh, it has to be a threadjob. It can't be foreach-object -parallel.

    $func = { 'hi' } # or
    function hi { 'hi' }; $func = $function:hi
    
    start-threadjob { & $using:func } | receive-job -auto -wait
    
    hi
    

提交回复
热议问题