首页 > 解决方案 > Powershell 在控制台和 ISE 中形成应用程序不同的输出

问题描述

我在 powersheel 中创建了复杂的表单应用程序,它也在 Powershell ISE 和 powershell 控制台中正常运行,但行为几乎没有区别:当我通过在 Windows 资源管理器中双击运行应用程序时,powershell 控制台打开,但有太多“调试”创建所有表单控件(复选框、标签、按钮...)的数据。启动时间太长,看起来像这样: TextImageRelation : Overlay UseMnemonic : True UseCompatibleTextRendering : True UseVisualStyleBackColor : True AccessibilityObject : ControlAccessibleObject: Owner = System.Windows.Forms.CheckBox, CheckState: 0 AccessibleDefaultActionDescription : AccessibleDescription : AccessibleName : AccessibleRole : Default AllowDrop : False Anchor : Top, Left AutoScrollOffset : {X=0,Y=0} LayoutEngine : System.Windows.Forms.Layout.DefaultLayout BackgroundImage : BackgroundImageLayout : Tile BindingContext : {} Bottom : 208 Bounds : {X=165,Y=190,Width=96,Height=18} CanFocus : False CanSelect : False Capture : False CausesValidation : True ClientRectangle : {X=0,Y=0,Width=96,Height=18}

此输出不在 powershell ISE 中(没有) - 应用程序立即启动。

我无法解决此问题,如果可能的话,我想在从控制台运行时删除调试输出 - 以加快脚本启动。

脚本源代码与互联网上的示例相同,例如: https ://docs.microsoft.com/en-us/powershell/scripting/samples/creating-a-custom-input-box?view=powershell-7

我试过哟添加| Out-Null 到一些控件/行 - 我在日志中看到,但它没有帮助。

我还尝试通过手动向控制台添加一些控件来确定哪个命令正在输出,但没有一个生成该输出。

我尝试创建 ISE 配置文件并将其加载到从控制台运行的脚本中,但没有帮助,因为创建的配置文件是空的。

如果我像这样运行新的控制台窗口: start-process powershell -argumentlist "-noexit", "-noprofile"并从中运行脚本,它可以在没有日志的情况下工作。但是如果我像这样运行脚本: start-process powershell -argumentlist "-noexit", "-noprofile", "-command $path" 它会再次输出日志。

任何想法如何做到这一点?我应该检查/修改什么。

谢谢你。

标签: formspowershell

解决方案


已解决:问题是我在评论中提到的脚本名称中的空格。


推荐阅读