什么可能导致由 powershell 脚本调用的可执行文件在退出时挂起
我正在调试一个特别奇怪的问题...
作为我团队测试套件的一部分,我们运行一个 powershell 脚本,该脚本调用我用 C# 编写的可执行文件。
每个周二,可执行文件都会无限期地挂起,直到我们终止该进程。大多数时候它工作得很好,而且我还没有重现它。
奇怪的是,这个 exe 在完成所有工作后挂起。输出最后一行数据,主线程退出。这个进程中没有多线程,CPU 为 0%,线程计数为 1。
所有 I/O(控制台写入除外)都在执行的早期完成,并且没有任何地方捕获异常,因此如果出现异常,我们应该看到它。
我不需要明确的“这就是问题”,但我不知道是什么会导致这种行为。如果你能用任何理论来解释为什么会发生这种情况(无论多么牵强),那就太好了。
版本信息
- 操作系统:Windows 2008 R2
- Powershell:v2(R2 附带)
- .NET:v4
I'm debugging a particularly strange problem...
As a part of my team's test suite, we run a powershell script that calls an executable I wrote in C#.
Every blue-mooned Tuesday, the executable will hang indefinitely until we kill the process. Most days it works just fine, and I haven't gotten it to repro.
The curious part is that this exe hangs after it's done doing all it's work. It's output the last line of data and the main thread is exiting. There's no multithreading in this process, and CPU is at 0% and thread count is 1.
All I/O (other than console writes) is done earlier in the execution, and there's no exception catching anywhere, so if something throws we should see it.
I don't need a definitive "this is the issue," but I have no idea what could cause this behavior. If you could respond with any theories on why this would be happening (no matter how far fetched) that'd be great.
Version info
- OS: Windows 2008 R2
- Powershell: v2 (comes with R2)
- .NET: v4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
呵呵,这个值得一试。 有什么地方吗?
某条逻辑线的末尾
Heh, this is worth a shot. Got
anywhere at the end of some line of logic?
我的一个“C”控制台程序上有类似的行为。它通过“CMD.EXE”开始运行良好,但是当我通过“POWERSHELL.EXE”使用它时,它在执行结束时(系统地)挂起。
在此代码中,存在键盘池循环(
while (!_kbhit()
)),目前我通过消耗 (getch()
) 的 keydown 来解决问题我不明白为什么在 Powershell 脚本中 exe 文件的结果会受到 var 的影响。
I've got a behaviour like that on one of my "C" console program. It was well working started via "CMD.EXE" but when I use it via "POWERSHELL.EXE" it hang (systematicaly) at the end of exécution.
In this code, there are keyboard pooling loop (
while (! _kbhit()
), and at the moment I solve the problem by consuming (getch()
) the keydown that fired the last loop. I don't understand exactly why.In the Powershell script the result of the exe file is affected to a var.