forms - Start-Process powershell 未将结果添加到文本框
问题描述
我正在尝试将命令输出添加到文本框。但它什么也没做。我错过了什么?我直接在 Powershell 控制台中尝试了该命令,它工作正常,我可以在那里看到输出。但是为什么它没有在文本框中显示输出呢?
这是我的代码
$showstatussh = {plink admin@192.168.1.1 -pw '' -m E:\PSGTM\statussh.txt}
$button_click = {
$textboxResults.Text = Start-Process powershell -ArgumentList "-Command $showstatussh"
}
$Form = New-Object System.Windows.Forms.Form
$Form.Text = "my control"
$Form.Size = New-Object System.Drawing.Size(300,300)
$Form.StartPosition = "CenterScreen"
$Form.Topmost = $True
$StatusS = New-Object System.Windows.Forms.Button
$StatusS.Location = New-Object System.Drawing.Size(30,150)
$StatusS.Size = New-Object System.Drawing.Size(230,30)
$StatusS.Text = "Show Status"
$StatusS.BackColor = [System.Drawing.ColorTranslator]::FromHtml("#cdafa8")
$StatusS.Add_Click($button_click)
$textboxResults = New-Object System.Windows.Forms.TextBox
$textboxResults.Location = New-Object System.Drawing.Point(10,190)
$textboxResults.Size = New-Object System.Drawing.Size(100,20)
$Form.Controls.AddRange(($StatusS, $textboxResults))
$form.showdialog()
解决方案
我想我想出了解决方案
代替:
$button_click = {
$textboxResults.Text = Start-Process powershell -ArgumentList "-Command $showstatussh"
}
我做了:
$button_click = {
$textboxResults.Text = .$showstatussh
}
推荐阅读
- angular - Angular 8 FormArray 的 .Net Core API ModelState 错误
- angular - 更改控件属性后,垫子微调器不会隐藏
- arrays - 如何读取对象并存储到数组中
- react-native - 反应本机位置跟踪器应用程序中的 WebSocket 与套接字 io
- c# - 使用 Azure 管理 API 列出容器组失败并出现 System.Net.Sockets.SocketException
- java - 如何对上传到服务器的 java 代码运行测试
- oracle - 如何将整列 Oracle SQL 从另一个表插入到预先存在的行中?
- reveal.js - 我们如何为每张幻灯片(而不是每个片段)创建一个 PDF 页面?
- python - MySQL / Python Mysql 连接器仅在大型查询上没有结果
- google-app-engine - 从服务帐户进行身份验证。Google App Engine 中的程序化 IAP 身份验证失败