Powershell窗口消失,我无法读取错误消息 [英] Powershell window disappears before I can read the error message

查看:137
本文介绍了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 Scheduler调用脚本来直接调用脚本,则它可以正常工作.如果我从另一个脚本(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:\ script \ foo.ps1

Solution: powershell -noexit d:\script\foo.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:\script\foo.ps1

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

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