powershell:退出并没有真正退出 [英] powershell: exit doesn't really exit

查看:88
本文介绍了powershell:退出并没有真正退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在代表其他人调查一个问题,该人试图将 powershell 与我们的一种产品一起使用.我们的产品可以执行命令来执行操作,大多数人直接调用 .exe 就可以了.不过,一位用户正在使用此方法调用一些 powershell:

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)}

发生的事情是它永远不会退出,所以我们的软件会一直等待.脚本以一个简单的退出 0"结束,之前的行是调试输出,如果我们从外部取消进程,则会显示该输出,因此它会到达脚本的结尾 OK(是的,否则脚本运行良好).

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).

如果我删除退出命令并将其替换为 powershell 会话终止:

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

Stop-Process -Id $PID

然后它确实终止了,但当然退出代码不是 0 并且我们回滚更改,所以这不是一个合适的解决方法.

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.

否则,回到'exit 0',我可以看到带有发送参数的powershell.exe 仍然显示在任务管理器中;所以并不是说它正在退出,我们也没有接受它,它只是没有退出.

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?"

推荐答案

好的,确认,修改命令以使用 start/wait 调用 powershell.exe 修复它.我不知道为什么(它肯定到了脚本的结尾,好像我将出口更改为随机的东西一样,我会出错).

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).

问题还是解决了...

这篇关于powershell:退出并没有真正退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆