4

I'm investigating a problem on behalf of someone else who is trying to use powershell with one of our products. Our product can execute a command to perform an operation and most folk call an .exe directly which works fine. One user is calling some powershell though, with this method:

powershell -version 2.0 -NonInteractive -ExecutionPolicy ByPass -file ($ScriptsFolder)p4_commit.ps1 {"($Message)" ($Files)}

What happens though is that it never exits, so our software sits and waits forever. The script ends with a simple 'exit 0' and the line immediately before is a debug output which is presented if we cancel the process externally, so it's got to the end of the script OK (and yes, the script runs fine otherwise).

If I remove the exit command and replace it with a powershell session kill:

Stop-Process -Id $PID

Then it does terminate, but of course the exit code is not 0 and we roll back the changes, so it's not a suitable workaround.

Otherwise, back on 'exit 0' I can see that powershell.exe with the parameters sent is still showing up in task manager; so it's not that it's quitting and we're not picking that up, it just doesn't quit.

Alas, i'm not much of a powershell expert- so the question boils down to "What would stop exit exitting?"

2
  • Hmm, using Start /wait as described [here][1] seems to help... [1]: stackoverflow.com/questions/2041799/… Commented Feb 14, 2013 at 12:34
  • i guess you never reach the end of the script. By design calling powershell.exe -file ... will automatically close at the end of script execution, unless you explicitly specify -noexit Commented Feb 14, 2013 at 13:14

1 Answer 1

2

OK, confirmed, amending the command to call powershell.exe with start /wait fixes it. I have no idea why (it was definitely getting to the end of the script as if I changed the exit to something random i'd get it error out).

Still, problem solved...

Sign up to request clarification or add additional context in comments.

1 Comment

You may find Gordon Smith's answer useful: stackoverflow.com/questions/2041799/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.