Search code examples
powershellechostart-job

Get the output of sub jobs started with 'Start-Job' command of PowerShell


I have a PowerShell script with the following code:

$functions = {
    Function test_function() 
    {
        echo "hello world"
    }
}

Function test_launcher()
{
    $EO = Start-Job -InitializationScript $functions -ScriptBlock {test_function} | Wait-Job
    $KK = Receive-Job -Job $EO
    echo $KK    }

test_launcher

But I don't know why the 'Hello world' string is not printed out. Does anyone knows how to modify this code in order to get the result of subjob 'test_function' printed on the screen?


Solution

  • You need to retrieve the jobs you start - look at Receive-Job