简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM