Paebbels
Paebbels

Reputation: 16221

PowerShell executes Invoke-Expression calls NOT in order

I have a short PowerShell script which saves me typing time ... maybe in the future when this snippets works ...

The first Expression starts an executable with some parameters (an assembler). If this tool exits with no errors, a Python script is launched with the help of the Python launcher py.exe. In addition to this, I collect all formatted assembler files (*.fmt) and delete them.

When I run this script, the Python script is executed first and after that the assembler runs.

What am I missing here?

Invoke-Expression "..\asm\KCPSM6.exe -c4096 main_KC705.psm"

if ($LastExitCode -ne 0) {
    Write-Host "ERROR: KCPSM6.exe return with an error code." -ForegroundColor Red
    exit 1
} else {
    Invoke-Expression "py.exe -3 ..\py\psmProcessor.py -v main_KC705.log"

    $fileList = Get-ChildItem -Path ..\psm -Recurse -Filter *.fmt
    $fileList += Get-ChildItem -Path ..\lib -Recurse -Filter *.fmt
    $fileCount = $fileList.Count
    Write-Host "Deleting $fileCount temporary files."
    if ($fileCount -gt 0) {
        $fileList | Remove-Item
    }
}

Upvotes: 1

Views: 1426

Answers (1)

Paul
Paul

Reputation: 5861

Try to start it with Start-Process like this:

Start-Process X:\asm\KCPSM6.exe -argumentlist @("-c4096", "main_KC705.psm") -wait

For a greater reference on how to start executables look here:

Technet

Upvotes: 3

Related Questions