本文介绍了如何开始我刚刚定义的函数的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何开始我刚刚定义的函数的工作?

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.

我该怎么办?谢谢.

推荐答案

正如@Shay 指出的那样,需要为作业定义 FOO.另一种方法是使用 -InitializationScript 参数来准备会话.

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.

例如:

$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.

这篇关于如何开始我刚刚定义的函数的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 04:30