在我阅读错误消息之前,Powershell 窗口消失了 [英] Powershell window disappears before I can read the error message

查看:13
本文介绍了在我阅读错误消息之前,Powershell 窗口消失了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调用 Powershell 脚本时,如何防止被调用的脚本关闭其命令窗口.我遇到了一个错误,如果我能读懂错误,我相信我可以修复它.

When I call a Powershell script, how can I keep the called script from closing its command window. I'm getting an error and I'm sure I can fix it if I could just read the error.

我有一个 Powershell 脚本,它使用 .NET 类发送带有附件的电子邮件.如果我通过从命令行执行脚本或从 Windows 调度程序调用它来直接调用脚本,则它可以正常工作.如果我从另一个脚本(IronPython,如果这很重要)中调用它,那么它就会失败.所有场景在我的开发机器上都能正常工作.(我真的必须得到在我的机器上工作"的标志!)我收到了对 Powershell 的调用,它以显示命令窗口的方式发生,我可以在它关闭之前看到闪烁的红色.

I have a Powershell script that sends an email with attachment using the .NET classes. If I call the script directly by executing it from the command line or calling it from the Windows Scheduler then it works fine. If I call it from within another script (IronPython, if that matters) then it fails. All scenarios work fine on my development machine. (I really do have to get that "Works on My Machine" logo!) I've got the call to Powershell happening in a way that displays a command window and I can see a flicker of red just before it closes.

抱歉:Powershell 1.0,IronPython 1.1

Sorry: Powershell 1.0, IronPython 1.1

解决方法:powershell -noexit d:scriptfoo.ps1

Solution: powershell -noexit d:scriptfoo.ps1

-noexit 开关工作正常.我只是将它添加到我从 IronPython 传递的参数中.正如我所怀疑的,这是我自己可以解决的问题(执行政策,虽然我暂时设置为不受限制但没有任何影响,所以我想我需要更深入地研究).如果我遇到麻烦,我会再问一个问题.

The -noexit switch worked fine. I just added it to the arguments I pass from IronPython. As I suspected, it's something that I can probably fix myself (execution policy, although I did temporarily set as unrestricted with no effect, so I guess I need to look deeper). I'll ask another question if I run into trouble with that.

感谢大家的帮助.我了解到我需要更仔细地研究 powershell 开关,我可以看到很多将来证明有用的东西.

Thanks to all for the help. I learned that I need to investigate powershell switches a little more closely, and I can see quite a few things that will prove useful in the future.

推荐答案

尝试使用 -noexit 开关:

powershell -noexit d:scriptfoo.ps1

这篇关于在我阅读错误消息之前,Powershell 窗口消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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