-command's exit code is not the same as a script's exit code

后端 未结 3 1949
深忆病人
深忆病人 2020-12-06 04:05

I need to run a script with PowerShell -Command \"& scriptname\", and I would really like it if the exit code I got back from PowerShell was the same as the exit code th

3条回答
  •  天涯浪人
    2020-12-06 04:58

    How are you calling your script interactively?

    I have tried this and it seems to work OK, but I call it from DOS prompt, not within PowerShell

    C:\Temp>type foo.ps1
    exit 42
    
    
    C:\Temp>powershell -noprofile -nologo -noninteractive -executionpolicy Bypass -file .\foo.ps1
    
    C:\Temp>echo %errorlevel%
    42
    
    c:\Temp>
    

提交回复
热议问题