简体   繁体   中英

PowerShell: Invoke-Parallel throwing error with “start-process”

I'm using the Invoke-Parallel CmdLet that can be found at the link here . When I have some dummy code in my script block, it works correctly, but when I add a start-process... command it fails with an error saying

Get-RunspaceData : This command cannot be run due to the error: The system    
cannot find the file specified.
At c:\crm\Interfaces\Batches\Invoke-Parallel.ps1:592 char:13

My script block looks like so. Long story short, I'm feeding file names into a block, and I am telling a 3rd party application to use that file as an input for a process. When the start-process line is removed, it works, with it, it fails.

$childFiles| Invoke-Parallel -ImportVariables {
    $importformat = '-f ' + '"CU Imp P19 FI"'
    $importfile = '-d ' + $_ + " " + $user + " " + $pass        
    Write-Host $importformat + " " + $_
    start-process .\mmim.exe -ArgumentList  $user, $pass, '-l:1', 
    $importformat, $importfile -Wait -NoNewWindow
    return "blah"
}

Does anyone have any idea of what might be going on? My PowerShell version is the following

Major:5

Minor:0

Build: 10586

Revision: 117

Any help is greatly appreciated.

Each PowerShell runspace have its own current location. If Invoke-Parallel does not change current location of spawned runspaces to match current location of main runspace, then relative path .\\mmim.exe may be resolved to entire different executable or not resolved at all and produce given error.

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