[英]Powershell Output Question when running Forms
When I run my Forms code I have different objects that are added to the Form (buttons, labels, etc) I attache the objects to the form by using the command $Form1.Controls.Add([ObjectType])
. 当我运行Forms代码时,我有添加到Form中的不同对象(按钮,标签等),我通过使用命令
$Form1.Controls.Add([ObjectType])
将对象附加到表单。
My question is, when I run my code I get an instant sequence of numbers in my console and output dialogue box of: 我的问题是,当我运行代码时,在控制台和输出对话框中会得到一个数字的即时序列:
0 1 2 3 4 5 6 7 8 9 0 1 2
When after I click Submit button the string "OK" is added to the numbers shown above 当我单击“提交”按钮后,字符串“ OK”被添加到上面显示的数字中
0 1 2 3 4 5 6 7 8 9 0 1 2 OK
Why is this happening and how can I remove these or atleast omit them from displaying. 为什么会发生这种情况,以及如何删除这些内容或至少将它们从显示中忽略掉。 The OK displays once the Submit button is pressed.
按下“提交”按钮后,将显示确定。 OK
好
Some actions like .Add()
are producing output. 诸如
.Add()
类的某些操作正在产生输出。 To prevent this, pipe the output into the [void]
by adding | Out-Null
为了防止这种情况,请通过添加
| Out-Null
将输出通过管道传递到[void]
| Out-Null
at the end of the line or [void]
directly infront of the variable that is used, like: 在行尾或在所使用变量的正前方
[void]
处为| Out-Null
,例如:
$foo.SomethingThatGeneratesOutput() | Out-Null
or 要么
[void]$foo = SomethingThatGeneratesOutput
As T-Me has stated, to prevent output being generated when executing methods as you are use [Void]. 正如T-Me所说,为防止在执行[Void]的方法时生成输出。
[Void]$Form1.Controls.Add([ObjectType])
If your code is still returning unwanted data, open the script in PowerShell ISE, and execute the script line by line (select the line and press F8). 如果您的代码仍在返回不需要的数据,请在PowerShell ISE中打开脚本,然后逐行执行脚本(选择该行,然后按F8键)。 This will help you determine which line of code is generating output still.
这将帮助您确定哪一行代码仍在生成输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.