Powershell script gets stuck, doesn't exit when called from batch file

前端 未结 10 637
不知归路
不知归路 2020-12-24 11:08

I have a PowerShell script that connects to a web site, and parses its returned data (It\'s about importing a previously uploaded SQL file into the web site\'s data base). T

10条回答
  •  爱一瞬间的悲伤
    2020-12-24 11:59

    We had a similar issue. We wanted to call a powershell app from a piece of software that just had a box to enter "Command" and "Parameters" but although the powershell ran successfully (I could see the affected file updated.)

    Finally my coworker helped me figure it out Command needs to be:

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 
    

    And Parameters:

    -ExecutionPolicy unrestricted -Command "& {C:\scripts\apps\EDI\Test.ps1; [Environment]::Exit(1)}"
    

    In our case it was important to use [Environment]::Exit(1) rather than Exit 1. I believe Exit was simply terminating the script, not closing Powershell itself.

提交回复
热议问题