相关疑难解决方法(0)

如何并行多次执行PowerShell函数?

我不知道需要多线程,工作为主,或异步,但基本上我有一个PowerShell脚本函数,它的几个参数是否调用这个,我需要使用不同的参数调用了几次,有这些运行在平行下.

目前,我调用这样的函数:

Execute "param1" "param2" "param3" "param4"
Run Code Online (Sandbox Code Playgroud)

如何在不等待每次调用Execute返回调用者的情况下多次调用它?

目前我正在运行v2.0,但如有必要,我可以更新

编辑:这是我到目前为止,这是行不通的:

$cmd = {
    param($vmxFilePath,$machineName,$username,$password,$scriptTpath,$scriptFile,$uacDismissScript,$snapshotName)
    Execute $vmxFilePath $machineName $username $password $scriptTpath $scriptFile $uacDismissScript $snapshotName
}

Start-Job -ScriptBlock $cmd -ArgumentList $vmxFilePath, $machineName, $username $password, $scriptTpath, $scriptFile, $uacDismissScript, $snapshotName
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

无法将'system.object []'转换为参数'initializationscript'所需的'system.management.automation.scriptblock'类型.不支持指定的方法

编辑2:我修改了我的脚本,但我仍然得到上面提到的错误.这是我的mod:

$cmd = {
    param($vmxFilePath,$machineName,$username,$password,$scriptTpath,$scriptFile,$uacDismissScript,$snapshotName)
    Execute $vmxFilePath $machineName $username $password $scriptTpath $scriptFile $uacDismissScript $snapshotName
}

Start-Job -ScriptBlock $cmd -ArgumentList $vmxFilePath, $machineName, $username $password, $scriptTpath, $scriptFile, $uacDismissScript, $snapshotName
Run Code Online (Sandbox Code Playgroud)

powershell asynchronous

27
推荐指数
3
解决办法
6万
查看次数

在父级恢复执行UNIX之前等待所有子进程

在我的程序中,我在一个有限的while循环中分支(并行)子进程,并在每个进程上执行exec.我希望父进程在所有子进程终止后才恢复执行(此while循环后的点).我该怎么办?

我尝试了几种方法.在一种方法中,我在while循环之后使父进行暂停,并且仅当waitpid返回错误ECHILD(没有剩余子进程)时才从SIGCHLD处理程序发送一些条件但是我在这种方法中遇到的问题甚至在父进程完成所有进程之前,retStat变为-1

    void sigchld_handler(int signo) {
        pid_t pid;
        while((pid= waitpid(-1,NULL,WNOHANG)) > 0);
        if(errno == ECHILD) {
            retStat = -1;
        }
    }

    **//parent process code**
    retStat = 1;
    while(some condition) {
       do fork(and exec);
    }

    while(retStat > 0)
        pause();
//This is the point where I want execution to resumed only when all children have finished
Run Code Online (Sandbox Code Playgroud)

c unix fork

12
推荐指数
1
解决办法
4万
查看次数

标签 统计

asynchronous ×1

c ×1

fork ×1

powershell ×1

unix ×1