如何调试 PowerShell 后台作业?
Jason Archer 帮助我解决了我的上一个问题,但在测试他的解决方案时,我偶然发现了真正的问题。我的服务器无法正确运行链接的后台作业,但我的笔记本电脑可以。
如果我在笔记本电脑上运行上一个问题中的脚本,它们就可以完美运行。脚本 A 将脚本 B 作为后台作业启动,脚本 B 从该作业中调用脚本 C,并接收所有输出。如果我在服务器上运行完全相同的脚本,脚本 A 会调用脚本 B,并且脚本 B 会无限期挂起。如果我直接运行脚本 B,它可以在服务器或笔记本电脑上完美执行。这份工作的背景让我很恼火。
$PSVersionTable 在所有计算机上返回相同的结果,但显然我必须在 WinXP 和 Win2003R2 上使用不同的安装程序。
是什么可能导致行为差异?
有什么方法可以解决后台作业中发生的问题吗?如果我可以看到正在接收的命令行(我已经记录了正在发送的内容,但有时事情会漂移),或者什么对象真正挂着东西,也许会有帮助,但调试器不会带我去那里。也许有一种方法可以在 ISE 中调用该作业,就好像它在后台运行一样?
Jason Archer helped me solve my last issue, but in testing his solution I stumbled across the real problem. My server won't run chained background jobs correctly, but my laptops will.
If I run the scripts in the previous problem on my laptops, they work perfectly. Script A starts Script B as a background job, and Script B calls Script C from within that job, and all output is received. If I run the exact same scripts on my server, Script A calls Script B, and Script B hangs indefinitely. If I run Script B directly, it executes perfectly on the server or the laptops. It's something about the job being backgrounded that's killing me.
$PSVersionTable returns the same results on all computers, though obvious I had to use different installers on WinXP vs Win2003R2.
What might be causing the difference in behaviour?
Is there any way to troubleshoot what's going on in the background jobs? If I could see the command lines being received (I've logged what's being sent, but sometimes things drift), or what object is really hanging things, maybe it would help, but the debugger won't take me there. Perhaps there's a way to call the job within the ISE as if it were running in the background?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
啊。我想也许我已经有了答案。
笔记本电脑:
服务器:
如果有人可以确认这一点或提供有关后台作业故障排除的信息,我将标记已回答的问题。
Ah. I think maybe I have my answer.
Laptop:
Server:
If anyone can confirm this or give info on troubleshooting background jobs, I'll mark the question answered.
您可以使用接收作业获取Powershell作业的输出结果。例如,如果我们有如下的工作:
我们可以得到这样的工作输出:
You can get the output result of a Powershell job by using Receive Job. For instance, if we had a job like as follows:
We could get the output of the job like this: