c# - C# Powershell 脚本未写入 Visual Studio 中的输出
问题描述
我有一个简单的 WPF 表单,我希望将某个 powershell 脚本的输出写入 Visual Studio 输出。但是,我在 Visual Studio 中没有得到正确的输出。
电源外壳:
nmap -O 198.168.1.1/24
我现在有一个只有一个按钮的 wpf 表单,代码如下:
MainWindow.xaml.cs:
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Debug.WriteLine("I am Here!");
PowerShell ps = PowerShell.Create();
ps.AddScript(@"C:\Research\Network Scanner\powerscript.ps1");
Collection<PSObject> resultsN = null;
resultsN = ps.Invoke();
Debug.WriteLine(resultsN);
// ps.Invoke();
}
}
}
输出:
我在这里!
线程 0x4378 已退出,代码为 0 (0x0)。System.Collections.ObjectModel.Collection`1[System.Management.Automation.PSObject]
解决方案
这会有所帮助。foreach(结果中的 PSObject obj) { Debug.WriteLine(obj.ToString()); }
推荐阅读
- r - 创建 2 个变量,它们为我提供 var1_A 到 var1_E 中的值,对应于 var2_A 到 var2_E 中的最高值
- time-complexity - 两个不同递归函数相互调用的时间复杂度
- python - Selenium chromedriver 无法启动错误“会话不是从选项卡创建的崩溃”
- python - gsettings 的奇怪行为用 cron 设置了一个新的 desktop.background
- reactjs - .header { 显示:弹性;justify-content:空格之间;这个 header.css 文件没有显示任何效果会是什么麻烦?
- bash - 在 Mac 环境变量中使用算术运算符设置字符串
- c - 如何使用 LAME 编码器库从 PCM (WAV) 文件中检索 ID3 标签信息?
- mysql - 在 SQL 窗口函数中考虑名声
- python - 在通过 VPS 连接的 putty 上筛选 Python 文件
- javascript - 我如何在反应中使用分页中的下一步和预览按钮?